Leading 0's syntax error in datetime.date module (Python 3.6)

bartc bc at freeuk.com
Thu May 10 18:43:25 EDT 2018


On 10/05/2018 18:58, Skip Montanaro wrote:
>> I wonder why someone would take a feature generally agreed to be a
>> poorly designed feature of C, and incorporate it into a new language.
> 
> I think you might be looking at a decision made in the late 1980s through a
> pair of glasses made in 2018.
> 
> As a C programmer back then I never had a problem with C's octal number
> notation. People coming from C, C++ or Java to Python at that time would
> certainly have understood that syntax. It's only in the past 15 years or so
> that we've seen tons of people coming to Python as a first language for
> whom leading zero notation would be unfamiliar.

I'm pretty sure I would have had exactly the same opinion in 1989.

Decimal numbers in code should reflect their usage in everyday life as 
much as possible.

And in everyday life, leading zeros do not change the base of a number 
so that it becomes octal. If my car odometer says 075300, it means I've 
done 75,300 miles or km, not 31424:

    mileages = (         # python 2
         215820,
         121090,
         075300,
         005105)

    for m in mileages:
         print m,"miles"

Output:

    215820 miles
    121090 miles
    31424 miles
    2629 miles

This is Wrong, and would have been just as obviously wrong in 1989.

-- 
bartc



More information about the Python-list mailing list