I'm not from a Matlab/Octave background, so one-based indexing feels really foreign to me.
I'm not from a Matlab/Octave background, so one-based indexing feels really foreign to me.
Edit: For a history of 0-based indexing see http://exple.tive.org/blarg/2013/10/22/citation-needed/ My understanding is that with modern compilers, there's no need for 0-based indexing; you can use 0-base, 1-base, or 69-base indexing as you prefer. 0-base is applicable to people creating chips or writing hardware drivers. Most scientific programmers are not so closely tied to hardware; 1-based indexing is one of the things that helps make Julia more accessible to high-school programmers or PhD students who don't want to learn binary arithmetic.
It's never been needed, Pascal had arbitrary array bounds (including negative) 50 years ago.
> 1-based indexing is one of the things that helps make Julia more accessible to high-school programmers or PhD students who don't want to learn binary arithmetic.
What does binary arithmetic have to do with anything? And have there been any study pertaining to the accessibility of 0-indexed versus 1-indexed arrays to high-scool programmers which would warrant such an assertion?
One based indexing counts, or labels boxes. Counting implies no "holes", but abandons any implication about how they are laid out in storage. Labelling allows treating numerical arrays as sparse hash tables, with as many "holes" as needed. It's a high level view, suited to mathy ways of thinking about data.
If I want to build a hash table, a power of two size for the underlying array is a nice performance optimization since you can use a bitmask instead of a modulo operation, and it makes a big performance difference, what does one-based give you other than some nebulous "it just _seems_ simpler to think about" kind of nonsense? I love how we expect people to grok the type system but we're afraid zero-based arrays will scare mathematicians off.
See: https://en.wikipedia.org/wiki/Modular_arithmetic#Integers_mo...
Coming from a regular programming background, as opposed to a technical computing background, can certainly make this look alien. However, I think it starts feeling natural quickly. There are many other things in Julia that can take a lot longer to get used to.
Btw, Matlab also uses 1-based indexing, no? I thought that Julia chose 1-based indexing to get brain backwards compatibility with Matlab.
I think zero based is "prettier" because of half open intervals, but it really doesn't matter.
Wouldn't it be possible to create array classes in Julia that all indexed zero-based? I would welcome a 'Julia0' fork :-)