3 ms·
I've never understood why this bugs people so much. I switch between languages with zero-based and one-based indexing about every hour or so. Never had a proble
by staunton 3y ago
I've never understood why this bugs people so much. I switch between languages with zero-based and one-based indexing about every hour or so. Never had a problem beyond the usual "off-by-one's" that I do anyway even without switching.
You have to keep track of which language you're using anyway to produce correct syntax...
- j-pb 3y agoJulia aims to also be a C-Compatible low-level language with manual memory management in addition to the GC. When building data-structures you're often using small unsigned integers that use the complete value-space, (e.g. u8s and their bitsets in tries, u16s and blocks with that size in sparse vectors). With 1 based indexing, you can't do that anymore without first having to cast the index into the next larger integer, adding 1, and then doing the access, which is a PITA, adds instructions, and messes with prefetching, while you're already working with difficult, hard to read, and heavily optimised stuff.
- raccoonDivider 3y agoWhy can't the compiler decrement indices as needed? It makes sense to keep 0-based indexing in the final binary, but the language's design doesn't constrain that.
- daynthelife 3y agoMy issue with one based indexing is more philosophical in nature. I truly believe to the core of my being that zero is the first number, and that indexing from one is simply wrong. The evidence leading me to this conclusion is that I have yet to know of a single instance where a procedure or mathematical formula becomes simpler when indexing from one; yet there are so many that become simpler when indexing from zero. To this extent, I find it almost offensive that a language geared toward mathematicians would intentionally choose to index from one.