

[Python-ideas] List Revolution - telemachos
http://mail.python.org/pipermail/python-ideas/2011-September/011448.html

======
famousactress
Guido admits this is a joke later in the thread:

 _(And to those taking the thread seriously: this is all in jest. We won't
change the indexing base. The idea is so preposterous that the only kind of
response possible is to laugh with it.)

\--Guido_

[http://mail.python.org/pipermail/python-
ideas/2011-September...](http://mail.python.org/pipermail/python-
ideas/2011-September/011462.html)

------
LeafStorm
Roberto Ierusalimschy has an interesting perspective on the zero vs. one
concept:

"Because _people_ count from one, not zero.

We do that in kindergarten, in music, when starting a race, when drawing up an
agenda, everywhere. One, two, three, etc have their counterparts in every
known language on earth.

Zero, on the other hand, is an advanced concept. Humanity could prove that
sqrt(2) is not a rational number centuries before anybody thought that a
symbol for zero might be useful.

A harder question would be "why do arrays in some other languages count from
zero not one?" The answer for C is a good one: "so that * (A+k) and A[k] mean
the same". For Python, the answer seems to be "because it's that way in C"."

And:

"Currently, many languages are 0-based due to influence from C. Ironically,
none of them share the reason that made C 0-based (where a[e] means * (a+e))."

(EDIT: I had to add spaces after the stars to prevent HN from italicizing a
huge block of text.

~~~
oxtopus
Meanwhile, some people do count up from zero. At least in numbering floors in
a building. I know in Europe and other parts of the world the ground floor is
the zeroth floor, and it goes up from there.

~~~
dkersten
Numerically, yes, but nobody calls it a "zeroth" floor. Rather, its "ground",
"first", "second" (or G, 1, 2, 3...) so while ground is equivalent to zero,
nobody actually says (or thinks) zero. At least, nowhere I've been.

~~~
inportb
So let's just call it the "ground" index.

    
    
      G = ground = 0;
      A[G], A[1], A[2], ...

------
tkaemming
The Dijkstra transcript referred to a bit deeper in the thread about why
sequence numbering starts at zero is a tangentially interesting read:
[http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...](http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html)

~~~
jemfinch
I specifically paged through the read to make sure that link had been given,
and then came to this comment page to do the same thing.

Few people seem to know that we have real and valid _reasons_ for indexing
from 0 instead of 1.

~~~
sid6376
Apologies if this appears dumb. After going through the link I still could not
understand why is it ok to exclude the upper bound while including the lower
bound? Is it because the lower bound is fixed as 0 is the smallest natural
number? Or is there some other reason.

~~~
ColinWright
Dijkstra explains it pretty clearly - there are two main reasons.

The first is so that the number of elements in the
array/list/vector/collection is given by upper-lower.

The second is so that successive intervals re-use the same number, the upper
bound of one becoming the lower bound of the next.

This is python we can have:

    
    
        L[:3], L[3:6], L[6:23], L[23:40], L[40:]
    

With the repeated numbers we know that all elements of L have been included.
Further, we know that given:

    
    
        L[start:end]
    

... then (provided L had at least "end" elements to start with) the resulting
length is _end-start_. If you included the end point then the length would be
_end-start+1_ which is fertile ground for fence-post errors.

~~~
noahl
But both of those things would be true if you include the upper bound and
don't include the lower bound. I.e. if an array with bounds 0 and 4 had items
in positions 1, 2, 3, and 4.

~~~
ColinWright
Yes, and that question is covered in the Dijkstra paper.

If you're talking about numbers from 13 onwards, it doesn't really make sense
to talk about numbers greater than 12. More specifically, if you start
counting from 0 then it feels (to me) more natural to include the lower bound.

If you talk about {5 .. 13} then it feels easier to say

    
    
        "From 5 up to (but not including) 13,"
    

rather than saying

    
    
        "From 5, er, sorry, no, from *6* up to and including 13."
    

There is a question of taste here, as well as background and experience. Don't
expect it to be "objectively proven."

<http://www.paulgraham.com/taste.html>

In the end it is all about convention, and what ends up making code cleaner,
less error-prone, and more aesthetically pleasing. As I say, there are
questions of taste _and_ experience. Personally I find the Dijkstra/Python
method for more consistent and pleasing than the alternatives.

~~~
psykotic
Another reason: Wrap-around with modular reduction is a snug fit, so it's L[i
% n] rather than L[1 + i % n]. You could have taken 1, 2, ..., n or indeed any
set of n integers with distinct residue classes modulo n as the
representatives, but the standard choice in mathematics is 0, 1, ..., n-1 for
consistency with the division theorem.

It is often very inconvenient when mathematicians number from 1 instead of 0.
A classic example is with Fourier matrices. Let w be a primitive nth root of
unity. Then numbering as computer scientists, starting with 0, the formula is
F(i,j) = w^(i j). But using the mathematician's convention, it is F(i,j) =
w^((i-1)(j-1)). The same issue exists with all Vandermonde matrices.

------
pyre
Good news! You can have this right now in Perl:

    
    
      $[ = 1;
    

Now all of your arrays are 1-indexed!

~~~
vessenes
I am truly, truly horrified that this a language option in perl, although I'm
not surprised. (Well, I did google it to see if you were joking, but you
weren't, apparently).

The older I get the more Larry Wall strikes me as like a really well
intentioned hippy type; when in God's green earth has it been a good idea to
allow a five character statement change the truth values of nearly every for
loop in a body of code?

Perl always claimed it gave you enough rope to hang yourself, but this goes
far, far beyond that. This is like building the scaffolding and marking it
like "Young developers, play here! Ropes are fun!"

~~~
irahul
> I am truly, truly horrified that this a language option in perl, although
> I'm not surprised.

How about this in C(and thousand others): #define if while

I am pretty sure I can find something to horrify you in almost any language.

~~~
Jach
Let's throw in a fun Python hack too:

    
    
        >>> import sys
        >>> import ctypes
        >>> pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5))
        >>> five = ctypes.cast(id(5), pyint_p)
        >>> 2 + 2 == 5
        False
        >>> five.contents[five.contents[:].index(5)] = 4
        >>> 2 + 2 == 5
        True

~~~
phzbOx
May I ask how did you find about that? Sometime I would like to play in ctypes
but I'm not sure where to start :-/

Here's a small snippet that let you add methods to built-ins:

    
    
      def inject(cls, wrapper=lambda x: x, name=None):
          def _builtin_hack(name):
              import ctypes as c
      
              _get_dict = c.pythonapi._PyObject_GetDictPtr
              _get_dict.restype = c.POINTER(c.py_object)
              _get_dict.argtypes = [c.py_object]
      
              return _get_dict(name).contents.value
      
          def wrap(method):
              name_ = name or method.func_name
              method = wrapper(method)
      
              try:
                  setattr(cls, name_, method)
              except:
                  _builtin_hack(cls)[name_] = method
      
          return wrap  
    
    
        @inject(dict)
        def extend(self, new_dict):
            return dict(self, **new_dict)
    
        print {'a':2}.extend({'b':3})

~~~
Jach
ctypes is like god-mode for Python... I like your hack too. I just play around
with it from time to time, I believe the only "serious" thing I've done with
it so far is making a Python interface around a C library I made.

I think I discovered the hack when I found out about the id() function, and
hex(id(5)) looked suspiciously like a pointer value. (And
<http://docs.python.org/library/functions.html#id> confirms.)
<http://docs.python.org/library/ctypes.html> has usually been pretty useful.
Apart from that, just play.

------
sixtypoundhound
He's joking right - I almost spit out my diet coke... (oh yeah...I'm sure THAT
will accelerate my group's upgrade from 2.66....)

------
makeramen
woah.

(not to post something useless, but I'm literally speechless going back and
forth between "that's so awesome" and "that's so dumb" in my head for so many
different reasons)

(and at how short and quick Guido's response was, as if it was such an easy
decision to make.)

~~~
sgk284
I suspect you're overlooking Guido's sense of humor. He was making a joke with
his acceptance of the idea.

~~~
makeramen
ah ok, not that familiar with Guido, but that makes much more sense haha

edit: also found this later in the thread to confirm the humor behind
everything: [http://mail.python.org/pipermail/python-
ideas/2011-September...](http://mail.python.org/pipermail/python-
ideas/2011-September/011454.html)

------
sagarun
_Well, given Guido's endorsement, I think we need to change how these +1/-1
votes work. Clearly, +1 means what +0 used to mean. So you have to say +2 to
vote in favor of something and -0 to vote against. I know it will be confusing
during the transition period but it will be so much easier to use when we are
done._

Loved this response [http://mail.python.org/pipermail/python-
ideas/2011-September...](http://mail.python.org/pipermail/python-
ideas/2011-September/011454.html)

------
briancurtin
First time I've laughed from a Python mailing list in a while.

------
mattbillenstein
That is clearly a freaking insane idea in a language as widely deployed as
Python...

~~~
sp332
Don't worry, it's not going in until version 4, and version 3 isn't even the
most common version yet.

~~~
cpeterso
Is that Python 3 or Python[3]??

------
gtklocker
I don't want to live in this planet anymore.

------
par
The benevolent dictator for life has spoken!

------
drivebyacct2
I hope it's obvious that it's a joke, but was the question serious is my
concern.

