Annoying octal notation
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Aug 23 00:07:05 EDT 2009
On Sat, 22 Aug 2009 14:04:17 -0500, Derek Martin wrote:
>> These human programmers, whether newbies or long-experienced, also deal
>> with decimal numbers every day, many of which are presented as a
>> sequence of digits with leading zeros — and we continue to think of
>> them as decimal numbers regardless. Having the language syntax opposed
>> to that is
>
> ...consistent with virtually every other popular programming language.
A mistake is still a mistake even if it shared with others.
Treating its with a lead zero as octal was a design error when it was
first thought up (possibly in C?) and it remains a design error no matter
how many languages copy it. I feel your pain of having to unlearn
something you have learned, but just because you have been lead astray by
the languages you use doesn't mean we should compound the error by
leading the next generation of coders astray too.
Octal is of little importance today, as near as I can tell it only has
two common uses in high level languages: file umasks and permissions on
Unix systems. It simply isn't special enough to justify implicit notation
that surprises people, leads to silent errors, and is inconsistent with
standard mathematical notation and treatment of floats:
>>> 123.2000 # insignificant trailing zeroes don't matter
123.2
>>> 000123.2 # neither do insignificant leading zeroes
123.2
>>> 001.23e0023 # not even if it is an integer
1.23e+23
>>> 000123 # but here is matters
83
--
Steven
More information about the Python-list
mailing list