Do you know where your variables are? | |
PerlMonks |
Re: why the array index has to start at 0??by kubrat (Scribe) |
on Jun 23, 2009 at 11:06 UTC ( [id://773965]=note: print w/replies, xml ) | Need Help?? |
That's actually a very good question. The most common explanation you'll find is because the index represents an offset from some memory address, so naturally the address of the first element will be at offset 0. But there's another reason which I came across some time ago and was very well explained by some mathematician. It was something to do with boudary checks and the argument was that i<10 is better than i<=10. Unfortunately, I can't remember the details nor can I find the web page. There are some situations where having the index start at 1 is needed like in some matrix computations if I am not mistaken. But that's not a problem in any language. Update: It was really bugging me that I couldn't recall who put the really good range argument, so I kept looking for it and here it is:
The argument was put by none other but E.W. Dijkstra Taken from http://lambda-the-ultimate.org/node/1950
In Section
Seekers of Perl Wisdom
|
|