4 ms·
As a student, I had way more difficulty adjusting to Matlab/Octave being 1-indexed than my first programming language being 0-indexed. It's very rare (and not a
by surement 10y ago
As a student, I had way more difficulty adjusting to Matlab/Octave being 1-indexed than my first programming language being 0-indexed. It's very rare (and not a good sign if you're doing it: use a struct or tuple) to look for the "third" element in a list, and much more common to run through every element, and, for example, < is cleaner than <=.
- int_19h 10y agoIt depends on the context. It's actually pretty common to make queries like "give me the third element" in data analysis, especially when your data sources come as a vaguely organized mess. At the same time, it's not actually all that common to index elements in loops these days - most languages have some kind of a for-each construct that hides indices (and some, like Python, only have such a construct).
- NoodleIncident 10y agoBoth slices and the 'for i in range(N)' are 0-indexed.
- int_19h 10y agoYes, they are. My point was that when you enumerate collections in Python, it doesn't matter, because it's just `for x in xs: ...` - you don't actually see the indices. This is in response to "much more common to run through every element" in the parent comment - it's just not a relevant scenario for indexing in most languages today. But slices definitely are, yes.