Python Feature Request: Allow changing base of member indices to 1

Antoon Pardon apardon at forel.vub.ac.be
Wed Apr 18 06:07:12 EDT 2007


On 2007-04-14, Paddy <paddy3118 at googlemail.com> wrote:
> On Apr 14, 11:27 am, samj... at gmail.com wrote:
>> This is like the previous one. Please check for sanity and approve for
>> posting at python-dev.
>>
>> I would like to have something like "option base" in Visual Basic.
>> IIRC it used to allow me to choose whether 0 or 1 should be used as
>> the base of member indices of arrays. In Python, the same can be used
>> with strings, lists, tuples etc.
>>
>> This would mean:
>> foo = "foo"
>> => foo[1] == 'f'
>>
>> foo = ['foo', 'bar', 'spam' ]
>> => foo[1] == 'foo'
>>
>> foo = ('spam', 'eggs')
>> => foo[1] == 'spam'
>>
>> For convenience it should also affect the range function so that:
>>
>> range(3) = [1, 2, 3]
>>
>> because this is often used where arrays would be used in VB.
>>
>> Finally, when the programmer does not specify his choice of base at
>> the beginning of the program, the current behaviour of using 0 as base
>> should continue so that there is no problem with backward
>> compatibility.
>
> Here is a document giving good reasons for indexing to start at
> zero, as in Python.

I find he just picks the reasons he agrees with.

If you pick your values as a <= i <= b it has the advantage that
the bounds are explicit. No need to add or substract 1 from
one of the values to get the exact boundis. Now how much weight
you want to give this characteristic is open for debate but
the fact that it isn't even mentioned doesn't give me much
confidence in the author's ability to weight all the pro's
and con's.

> http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
> The author has done a bit:
> http://en.wikipedia.org/wiki/Dijkstra
>
> Having more than one index start point would be a maintenance
> nightmare best avoided. (It can be done in Perl).

It was never a problem when I still programmed in Pascal.

-- 
Antoon Pardon



More information about the Python-list mailing list