PBP: 038 Leading Zeroes

Best Practice: Don’t pad decimal numbers with leading zeroes.

In my mind, this isn’t a best practice.  It’s an error.  You can’t pad decimal numbers with leading zeroes – they turn into octal numbers and are wrong.

The book suggests people might do this to make columns of assignments line up.  If I liked that, and if I did it by hand it might be tempting, but I don’t.  I use spaces.  Better, I let perltidy via the editor use spaces and stop spending brain power on it.

The book also suggests not using leading zeroes for octal digits, and using the oct() function.  I think this is overkill.  Leading zeroes mean octal, use them as they need to be used.  Don’t add a run-time function call instead of just using the right constant because octal is unusual in this era.

I dislike having to make the assumption that the person reading this program doesn’t actually know the language and will be confused.

 

Leave a Reply