Damien Neil wrote:
On Thu, Dec 05, 2002 at 02:45:39AM -0800, Michael G Schwern wrote:

Explain how having indexes (arrays, substr, etc...) in Perl 6 start at 0
will benefit most users.  Do not invoke legacy. [1]

Answer 1: Ignoring legacy, it won't.
Bingo.

Answer 2: Because C uses 0-based indexes, Parrot is written in C, and
it would be just painful to switch back and forth when working on
different layers of the system.  (Not a legacy argument, unless you
want to argue that Parrot is a legacy system.)
I doubt "most users" will be writing Parrot.

Answer 3: In a lower-level language than Perl, an array is usually a
block of memory divided into array elements.  The index is the offset
from the start of the array.
Assuming the base index of the array is 0.  More generally, the index of an
array element is that element's offset from the base index of the array.
Your argument is somewhat circular.  I have oodles of arrays declared to
start at 1980.  Most of my arrays start at index 1.  But then I'm a Fortran
programmer.  (And I hope that's not an opening for a language war thread.)

Choice of language aside, having max_index == num_elements appeals to me. YMMV.

In any case, the choice of default base index is less important for Perl than
for other languages given how seldom arrays in Perl are accessed by index as
opposed to manipulated by push, pop, for $x (@array) loops and such.

brad

Reply via email to