4 ms·
The 1-indexed arrays can sometimes be nice, but I've run into bugs so many times when translating the code into a language with 0-indexed arrays.
by sghodas 10y ago
The 1-indexed arrays can sometimes be nice, but I've run into bugs so many times when translating the code into a language with 0-indexed arrays.
- tptacek 10y agoThat's interesting, because the 1-indexed arrays are primary the primary reason I don't ever seriously consider using Julia (or Lua); I can only shudder and imagine the obnoxious number of off-by-one mistakes I'd make.
- Avshalom 10y agoOn the other hand having cut my teeth programming in MATLAB and lua 1-based indexing is on of the things that endears Julia to me.
- ced 10y agoOut of curiosity, assuming that Julia magically had 0-indexed arrays, what would you use it for?
- jernfrost 10y agoI think this is a mental block people have. I grew up on zero based arrays in C, but I can't say this has caused me any issues thus far using Julia. I don't know how it is for others but for me I just into this mode where I think about Julia as doing math and I know in math you start at 1 for vectors and matrices. Besides the way functions and APIs work, you seldom have to write code that really depends on the start index.
- CyberDildonics 10y agoWhat you are saying is conjecture if you haven't tried Julia or Lua. The reality is that 1 based indexing is trivial compared to the difficulties of a complex program.
- deleted 10y ago[deleted]
- matt4077 10y agoYeah, it just feels wrong. Of course that's just habit and in fact starting counts at 1 is actually the more user-centric way of doing it. I wish I could get used to Julia but for some reason I just think the source looks..ugly. Maybe it's my dark past with php that makes me shudder at the sight of avg(x) (instead of x.avg). I know that's stupid (and the syntax is actually required for multiple dispatch). Maybe Julia and I should try couples' therapy.
- simonster 10y agoIf I can switch between programming languages that use 0-based and 1-based indexing without getting confused, surely you could too. If you don't think that learning to use 1-based indexing is worth it, that's fair enough, but it's pretty low on my list of things that give me trouble when I translate code between languages.
- jhbadger 10y agoBasically every mathematical/data science language uses 1-based arrays -- R, MATLAB, and Mathematica in addition to Julia. Probably because traditionally (and to a degree even now) the standard numerical language was FORTRAN.