this post was submitted on 19 Oct 2024
725 points (98.9% liked)
Science Memes
10905 readers
1924 users here now
Welcome to c/science_memes @ Mander.xyz!
A place for majestic STEMLORD peacocking, as well as memes about the realities of working in a lab.
Rules
- Don't throw mud. Behave like an intellectual and remember the human.
- Keep it rooted (on topic).
- No spam.
- Infographics welcome, get schooled.
This is a science community. We use the Dawkins definition of meme.
Research Committee
Other Mander Communities
Science and Research
Biology and Life Sciences
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- !reptiles and [email protected]
Physical Sciences
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
Humanities and Social Sciences
Practical and Applied Sciences
- !exercise-and [email protected]
- [email protected]
- !self [email protected]
- [email protected]
- [email protected]
- [email protected]
Memes
Miscellaneous
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Starting at 0 makes sense in low-level languages like C because it's not really an index but a memory offset. Higher level languages like SQL or MatLab correctly start at 1 because they abstract memory management away. Other languages without manual memory management, such as JavaScript or Python, are incorrectly starting their arrays at 0.
Almost every programming language uses 0.
So, I'm not alone... Thank you!
It's worth noting that a number of languages comparable C in use case and performance (including its predecessors COBOL, Fortran and ALGOL) start indexing at 1 just fine because they have proper array types and don't make heavy use of pointers poking and peeking wherever they like (eg by using references instead).
Decoupling indices from memory offsets doesn't get in the way of performance and actually often allows better optimization because the compiler knows you aren't sharing pointers between arrays or some other shenanigans; see Fortran, the GOAT of fast array processing. This also allows improved type safety and thus memory safety; see index types in Ada/SPARK and the fact that it's the only 'legacy' language that's gotten comprehensive compile-time memory safety analysis (though the latter is moreso from the less willy-nilly pointers in general)