Python "why" questions

Terry Reedy tjreedy at udel.edu
Fri Aug 13 18:09:49 EDT 2010


On 8/13/2010 11:27 AM, Den wrote:

>
> I smile every time I see the non-nonsensical sentence "The first
> thing, therefore, is in thing[0]" in a programming language learning
> book or tutorial.  I laugh every time I hear someone defend that as
> common sense.

If one thinks in terms of slicing at gap positions, the 'proper' indexes 
would range from 0.5 (average of 0 and 1) to n-0.5. For convenience, we 
round down or up. To put it another way, seq[n:n+1] is abbreviated as 
either seq[n] or seq[n+1]. Put this way, the first choice is at least as 
sensible as the second.

Given that Python allows indexing from both end, I prefer 0,1,2,... and 
-1,-2,-3,... to 1,2,3... and 0,-1,-2,... or 1,2,3,... and -1,-2,-3.

As someone else pointed out, discretizing a continuous variable starting 
at 0 gives 0,1,2,... so having indexes that match is handy.

If a problem is formulated in terms of 1,2,3, one can simply leave the 
first cell blank rather than reformulate. If a problem is formulated in 
terms of 0,1,2,... and indexes are 1 based, then one must reformulate.

>  Every three year old watching Sesame Street knows
> counting things starts with '1', not '0'.

And that is the same mistake that most societies make, the mistake that 
put a lid on Greak math, science, and finance. All fresh counts begin 
with 0. Counting by people usually begins with a silent 0, just as fresh 
tallies begin with a blank stick or paper.

But not always. For instance, lets count the people who have, up to noe, 
become billionaires with Python. We start with an overt 0. Now we can 
discuss whether the founders of Google should increase that to 2.

Mechanical counting requires an overt 0. A car odometer starts at 0, not 
1 and not  . Have you never written a counting program? Starting with n 
= 1 instead of n = 0 before counting the first item would be a bad bug.

> There may be loads of reasons for it, but don't throw common sense
> around as one of them.

I won't. Only a few (about 3 or 4) societies included a proper 0 in 
their number systems.

-- 
Terry Jan Reedy




More information about the Python-list mailing list