Python "why" questions

Russ P. russ.paielli at gmail.com
Thu Aug 19 14:57:53 EDT 2010


On Aug 19, 11:42 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Thu, 19 Aug 2010 11:03:53 -0700, Russ P. wrote:
> > For those who insist that zero-based indexing is a good idea, why you
> > suppose mathematical vector/matrix notation has never used that
> > convention? I have studied and used linear algebra extensively, and I
> > have yet to see a single case of vector or matrix notation with zero-
> > based indexing in a textbook or a technical paper. Also, mathematical
> > summation is traditionally shown as "1 to N", not "0 to N-1".
>
> In my experience, it's more likely to be "0 to N" than either of the
> above, thus combining the worst of both notations.
>
> > Are
> > mathematicians just too simple-minded and unsophisticated to understand
> > the value of zero-based indexing?
>
> No, mathematicians are addicted to tradition.

That is probably true. But computer languages are addicted to more
than tradition. They're addicted to compatibility and familiarity. I
don't know where zero-based indexing started, but I know that C used
it very early, probably for some minuscule performance advantage. When
C++ came along, it tried to be somewhat compatible with C, so it
continued using zero-based indexing. Then Java was loosely modeled
after C++, so the convention continued. Python was written in C, so
zero-based indexing was "natural." So the whole thing is based on a
decision by some guy who was writing a language for operating systems,
not mathematics or application programming.

> Unlike computer scientists, who create new languages with radically
> different notation and syntax at the drop of a hat, mathematicians almost
> never change existing notation. Sometimes they *add* new notation, but
> more often they just re-use old notation in a new context. E.g. if you
> see (5, 8), does that mean a coordinate pair, a two-tuple, an open
> interval, or something else?
>
> Additionally, mathematical notation isn't chosen for its ability to
> encourage or discourage errors. It seems often to be chosen arbitrarily,
> or for convenience, but mostly out of tradition and convention. Why do we
> use "x" for "unknown"? Why do we use i for an integer value, but not r
> for a real or c for a complex value?
>
> Mathematicians are awfully lazy -- laziness is one of the cardinal
> virtues of the mathematician, as it is of programmers -- but they value
> brevity and conciseness over notation that improves readability and
> robustness. That's why they (e.g.) they use implicit multiplication, a
> plethora of "line noise" symbols that would boggle even Perl programmers,
> and two-dimensional syntax where the meaning of tokens depends on where
> they are written relative to some other token. (E.g. subscript,
> superscript, and related forms.)
>
> There is one slightly mainstream language that uses mathematical
> notation: APL. The result isn't pretty.

As I wrote above, the use of zero-based indexing in C++, Java, and
Python are all simply based on the fact that C used it.

I wouldn't have guessed that APL is a "mainstream" language. As I
wrote in recent posts, Fortran, Matlab, and Mathematica all used one-
based indexing. Maybe Basic too, but I haven't checked.




More information about the Python-list mailing list