Array start index

jmh530 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 3 11:57:25 PDT 2015


On Saturday, 1 August 2015 at 09:35:53 UTC, DLearner wrote:
> Does the D language set in stone that the first element of an 
> array _has_ to be index zero?
> Wouldn't starting array elements at one avoid the common 
> 'off-by-one' logic error, it does
> seem more natural to begin a count at 1.
>
> Actually, maybe even better to allow array definitions of form
> int foo[x:y];
> (y >= x) creating integer variables foo[x], foo[x+1],...,foo[y].
>
> I think the (very old) IBM PL/I language was like this.

I come from matlab and R which start matrices at 1. I used to 
think it was more natural. However after I started using numpy I 
now think 0 index is better.
Also see 
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
Give it a try. You might find you like it.


More information about the Digitalmars-d-learn mailing list