Negative array indices
Thu, 15 Oct 1998 10:23:36 -0700
At 11:43 PM 10/14/98 -0700, Ka-Ping Yee wrote:
>On Thu, 15 Oct 1998, Tyler Close wrote:
>> A while back, Ping and Mark were considering accepting negative array
>> indices as counting from the back of the array rather than the front.
>> I would like register a protest. I think this cuts down on your ability to
>> catch programming errors.
>It is true that allowing negative indices may mask some bugs -- however,
>it's a question of weighing how often that is likely to occur against
>how often it will be convenient to be able to index from the back.
I personally like the idea of signaling error for negative array indexes.
(I like even more the idea of banishing negative numbers, but there I'm a
minority of one.)
To achieve what Ping likes in Java you do:
Object foo = blah...
Object fromBack = foo[foo.length - index];
Now we could talk about syntactic sugar which would make this more
palatable if foo were some complex, side-effect causing expression, but I
don't do syntax.