When is ten actually eight? When it starts with zero.
$ python -c 'print 010'
8
Base 8 notation is a bad left-over feature from the old days of 12 bit words when programmers only had eight fingers. Yet it persists in our modern computing environments, where almost everything has a magic rule that if a number starts with 0, it must be in octal.

The problem is people sometimes left-pad numbers with zeroes so they line up nicely. For instance, the wonderful ISO date format is written like 2004-09-15. If you're not careful and you try to convert that '09' into an integer, you may get an error because 9 is not a valid octal digit. It's worse with IP addresses: what does '063.194.075.026' mean? Well, that depends on who is reading it.

Octal is the cause of all sorts of contemporary bugs for modern ten fingered programmers. Even Javascript has this holdover from the old days, causing confusing errors when users type numbers into fancy forms.

The only place I've ever explicitly wanted octal was setting file modes with chmod. Because Unix permissions come in groups of 3, base 8 is convenient shorthand that's now deep in my brain. Ironically, chmod doesn't require a leading 0. chmod 600 secret.txt is implicitly assumed to be 0600, or 384.

techbad
  2005-01-21 18:03 Z