Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Honestly, I just wish that this was 0-indexed. 1-indexing annoys me enough that I haven't really started playing with Julia.


I don't get why people care about this. How often does that hit you in normal code? It never bothered me in Lua, and certainly not in Julia. For me I just do a context switch. I know when I am in Julia I have to think about things like in my mathematics books. Just like you index a matrix.

When I am in other languages like C/C++ I tell myself that I working with memory addresses. For memory addresses 0-index makes more sense. For tables, matrices etc I honestly think 1-based indexing makes more sense.

Only time I dislike 1-based indexing in Julia is when I write code which is strongly related to how memory works. Like when I was implementing a CPU simulator and assembler.


It depends on which kind of maths you refer to.

After studying ordinal numbers, I feel like the normal way to start counting is from 0 (or the "empty set" ordinal).

This is also how you prove something by transfinite induction, you need to start by 0.

I wish I could easily recompile Julia so that it is 0-indexed. But then what about all the libraries...


Most well-written libraries do not depend on the specific type of indexing in an array. There's a strong convention for writing index-agnostic code, with eachindex(), enumerate(), firstindex(), lastindex(), begin, end, etc.

I try to write code to accept 0-, 1-, 2-, and StarWars-based indexing.


There's nothing preventing you from using a 0-base, it's just extra work to implement. You can even use the fabled 2-base index! https://docs.julialang.org/en/v1/devdocs/offset-arrays/


For people complaining about 1-indexing, it is precisely because they wish what they feel the "natural" way to count would come without overhead.

So it's this "extra work" that is the problem.

It would be nice to have it as an environment variable or a runtime option. Then what about portability issues...

So let's just fork Julia and call it JuliB with 0-indexing =)


I wished python was 1-indexed. I can't count the number of times I made an error because somehow programming languages count from 0, which is insane. I also keep having to do dumb things like len(x)-1, which also is dumb.


It's mostly about habit. Apart from that, I really enjoy this venture into the history of 0-based vs. 1-based indexing: http://exple.tive.org/blarg/2013/10/22/citation-needed/

> the technical reason we started counting arrays at zero is that in the mid-1960’s, you could shave a few cycles off of a program’s compilation time on an IBM 7094. The social reason is that we had to save every cycle we could, because if the job didn’t finish fast it might not finish at all and you never know when you’re getting bumped off the hardware because the President of IBM just called and fuck your thesis, it’s yacht-racing time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: