5 ms·
I have a new meta-pet-peeve: people who are peeved by one-indexing. EDIT: I guess it went into his "differetn" category. Never mind.... Why is one-indexing
by forkandwait 13y ago
I have a new meta-pet-peeve: people who are peeved by one-indexing.
EDIT: I guess it went into his "differetn" category. Never mind....
Why is one-indexing at the top of his list of bad things, or even on a list of things that matter? It is like getting stuck on adjectives after the noun...
My opinion, not widely shared here, is that 1-indexing is best for scripting and math languages where 1-indexing corresponds directly to the subscripts in the formulas. In Numpy etc, you have spend a lot of time converting those formulas by subtracting one all over the place, introducing bugs and making stuff less readable.
The only reason to use zero index is when, like in C, you are calculating your distance from a memory boundary.
Sorry for the rant.
- paulclinger 13y agoIt's in the "other" section; neither good nor bad in my opinion, just different from (some) other languages.
- Pxtl 13y agoDijsktra on zero-based indexing: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW... Obviously the differences are small and it's not worth obsessing over, but I do think that zero-based approach works better with array code that involves offsets... and that's not the exclusive province of manually managed memory - array-index math can happen for many reasons. Of course, one-based math is more intuitive to the layperson, which is obviously why it's the natural choice for Lua.
- endianswap 13y agoAnd for those who didn't see this on HN a couple of days ago, here's Guido van Rossum on zero-based indexing in Python: https://plus.google.com/115212051037621986145/posts/YTUxbXYZyfi https://plus.google.com/115212051037621986145/posts/YTUxbXYZ...
- anonymous 13y ago1-based indexing is insane. In the literal sense. I can kind of conceive of a mind that doesn't run away when introduced to a 1-based language. Some young, inexperienced mind which doesn't understand numbers yet. I cannot at all conceive what madman would actually like 1-based indexing. Their mind must operate on principles completely alien to the rest of us and should, preferably, not be allowed to write programs.
- AlexeyBrin 13y agoI suppose you are simply trolling, otherwise a simple programming language history lesson will show you that one of the first compiled languages, Fortran, has one based indexes.
- anonymous 13y agoI wasn't trolling. It feels positively deranged. Like having all numbers be written in Roman numerals for instance. I don't get your point about Fortran. Deeply flawed languages have existed for a long time?
- GhotiFish 13y agoyou know. That little endian big endian story was meant to be a warning, not a guide. Zero works. One works. Zero works too.
- ANTSANTS 13y agoI agree with your argument about 1-based indexing being more intuitive for people with more math than programming experience. I'd even concede that, given Lua's history (as I understand it) as a tool for engineers at PUC-Rio, it would be strange if they hadn't adopted that convention. Lua is not just any "scripting" language trying to isolate itself from the rest of the world, though. Today it is arguably the most popular language for embedding purposes. It's typically used in reasonably large C or C++-based applications as a layer of easily and dynamically reconfigurable glue between components. As such, a large portion of its users are directly involved in maintaining the interface between the C and Lua worlds in their programs, to a much greater extent than with most other dynamic languages. Differing from C's convention for any reason is a small but constant source of annoyance and occasional bugs when working at this level. You accept the difference and learn to work around it, but it's yet another dumb-mistake-causing source of unnecessary cognitive load that seems out of place in a language mostly free of that characteristic. I think Lua's 1-basedness is a valid complaint for embedders. It's not a huge problem, it can be worked around. However, if the Lua devs (or Mike Pall) decided tomorrow that from then on out, Lua(JIT) would use 0-based indexing by default, it would only make my work easier.
- anonymoushn 13y agoI use this Lua all the time, and 1-based indexing is probably the second most bothersome thing in it. I end up talking to C++/Python/JS a lot, and they all happen to use the other convention.