Python handles globals badly.

Steven D'Aprano steve at pearwood.info
Tue Sep 8 11:56:04 EDT 2015


On Wed, 9 Sep 2015 12:31 am, Ian Kelly wrote:

> On Tue, Sep 8, 2015 at 5:55 AM, Vladimir Ignatov <kmisoft at gmail.com>
> wrote:
>>>> I had some experience programming in Lua and I'd say - that language
>>>> is bad example to follow.
>>>> Indexes start with 1  (I am not kidding)
>>>
>>> What is so bad about that?
>>
>> It's different from the rest 99.9% of languages for no particular reason.
> 
> It's not "different from the rest 99.9% of languages". There are many
> languages that use 1-based indexing, e.g. Matlab, Pascal, Fortran.

Correct. Nearly all natural languages start counting at 1, not 0, as do
quite a few programming languages, such as PL/I, Algol60 and others. You'll
note that languages that are designed for mathematics (Matlab, Mathematica,
Julia) tend to use 1-based indexes. This is not an accident.

Guido discusses why he choose 0-based indexing like in C, instead of 1-based
indexing like in ABC:

http://python-history.blogspot.com.au/2013/10/why-python-uses-0-based-indexing.html

He links to this fantastic discussion of why C ended up with 0-based
indexing:

http://exple.tive.org/blarg/2013/10/22/citation-needed/

It's a wonderful read.

See also:

http://c2.com/cgi/wiki?WhyNumberingShouldStartAtOne
http://c2.com/cgi/wiki?WhyNumberingShouldStartAtZero

Anyone who thinks that there is one right answer here simply isn't paying
attention.


> None of those are even the worst offender here, IMO. That honor goes
> to Visual Basic 6, where the default lower bound is 0, but the
> programmer has the option of declaring an array to use any lower bound
> they want, or even globally change the default. 

I'll just point out that some algorithms are best written with 0-based
arrays, and some are best with 1-based arrays. I shouldn't have to change
languages to change from one to the other!



-- 
Steven




More information about the Python-list mailing list