in reply to The Zeroeth Principle

There are times where you really need an index. However, this may not be as often as you think.

In nearly all cases, you are iterating through an array:

for $i ( 0 .. $#array ) { print $array[$i]; }

But Perl (and a surprising number of other languages, particularly functional ones) provide a way to do it without the index:

for $i (@array) { print $i; }

I'm told that there are even some langauges that have no way of indexing an array at all.

So when people get into debates about 0-vs-1 array indexes, or if array names should not be pluralized so that $list[1] reads better, I must wonder how often these people are using indexes. I would argue that using a lot of indexes is a result of a coder who doesn't really know the language. If you're not using array indexes, then why do you care if the array is indexed at 0 or 1 in your particular language? Why would you care if your language has indexes at all?

One of the few places where I do use indexes is in debugging--I sometimes want to know that the error occured at a certain spot in the array. Also, I use them when parsing xSV files, since I often want a specific entry in the given row.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re^2: The Zeroeth Principle
by Anonymous Monk on Aug 26, 2004 at 09:42 UTC
    If you don't have indices, you can't have slices, you can't splice, and you wouldn't be able to do a binary search, and you won't be able to use a Schwartzian Transform in the way you are used to do it now. Basically, if you give up indices, you give up random access into arrays, and you're downgrading arrays to linked lists. I'm very glad I don't program in languages that don't give me the full power of arrays.

      I don't necessarily advocate getting rid of indexes entirely, only note that it's possible. You're right, it would give up some powerful features (but not Turing Completeness).

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

        Why stop at the possibility of getting rid of indices? One doesn't give up Turing Completeness by getting rid of arrays.
Re^2: The Zeroeth Principle
by Anonymous Monk on Aug 26, 2004 at 09:47 UTC
    Most people would just write:
    print @array;
    and don't bother with the C-style vs. alias style discussion.