3 ms·
This is something I don't fundamentally understand. As someone who works a lot with MATLAB I'm very used to and like 1-based indexing. But when I use C or Pytho
by ModernMech 8y ago
This is something I don't fundamentally understand. As someone who works a lot with MATLAB I'm very used to and like 1-based indexing. But when I use C or Python, 0-based indexing is not something I complain about or hold against the language. It's just the way things are.
Maybe if you don't think of it in terms of a different index basis and instead you think of it as indexing vs. offsets then it becomes easier to switch between the two?
- ssivark 8y agoIf that's someone's biggest complaint against the language, then I'd say the language must be pretty awesome ;-) It's basically bikeshedding. "But I look at the shed all day..." "But I'm used to looking at reddish colors..." "Red is more correct than green because <yadda yadda>..." Let's all move on to more important things :-)
- zimablue 8y agoIt's not bikeshedding because: 1) it is pervasive and fairly importsnt 2) it's kind of a deep indication that something is amiss. It's like a language written in 2019 that has default dynamic not lexical binding, not in terms of importance but in terms of it's an argument that was had and decided 20 years ago. If this is wrong then you can probably assume that lots of other things which are important, decisions which can't be "proven" correct but have both convincing arguments and weighty empirical evidence are wrong (I'm not having that argument here but google why 0-based makes sense by Djikstra). I might have to learn Julia at some point but 1-based indexing was a fairly heavy indicator to me to hold off.
- improbable22 8y agoIndeed it's starting to sound rather more like a church than a bikeshed! I am curious what people write all day for this to be such a big issue. It's not like you need to re-invent N-dimensional array indexing every morning -- we have abstractions. If translating code then it could be from either convention... or from a mathematics book. (Where you may note that mathematicians are unconvinced by the CS arguments... admittedly not a group of people known for taste in all matters, but taste in notation they have thought about quite a bit.)
- ModernMech 8y agoI'm not convinced. I've written a great deal of software in C++ and MATLAB. I don't see what the big deal is either way. You say this thing has been "decided 20 years ago" (by whom?) but that's clearly not the case, as myriad languages that use 1-based indexing are in existence, continue to come into existence, and are used to great effect. You cite Djikstra's argument (well, you didn't actually cite it [1]) but his reasoning isn't exactly air tight; he appeals to subjective ideas of "ugliness" and "unnaturalness" and "preferences" and cites a single anecdote for Mesa as proof of his correctness, then dismisses FORTRAN, ALGOL, and PASCAL out of hand as a "pity". Again, I'm not convinced. [1] https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- zimablue 8y agoMuch like turing completeness, you can build systems with any choice that "work", so an argument always has to be from aesthetics, which can include simplicity and "uglyness", but these aren't totally individual (you can get 99/100 people to agree on which of two schemes is "simpler"). Simplicity and beauty aren't something that even mathematicians dismiss as they can be trying to tell you something. There's another argument, I can't remember if I originated it or read it but it's the one I find most convincing. Consider that you have finite units of equal length 1 stretching away from you in a line. How would you specify to someone (using real-number measurements) to retrieve the first N=6, or describe the vector they occupy? You would say, take everything between [0.0, 6.0). If you use zero-based indexing, the numbering scheme specifying the interval is identical across both systems: [0.0, 6.0) => (python)[0: 6]== 0<=x<6. In real numbers the interval could be open or closed for this argument to work, because for there to be any elegant translation the integer upper bound has to be open. That's the only way you can keep the elegant transformation with 0 and 6. Caveat that thie works because you're numbering the real-number origin as 0 but try telling physicists that they're not to do that! O=(1,1,1) is an even more indefensible position. So there's another mathematical argument that I either came up with or read elsewhere that feels deeply convincing to me. If there's 2 there's probably more, and here's the list of languages on wikipedia, you tell me which you'd rather work in. https://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28array%29#Array_system_cross-reference_list https://en.wikipedia.org/wiki/Comparison_of_programming_lang... Sorry for the irate tone but I really think that on reflection and fair consideration this is an obvious one.
- throwawaymath 8y agoYou’re repeating yourself without defending your point. Beating us over the head with how obvious something is to you doesn’t make your argument any more compelling. > it is pervasive and fairly important Why? > it's kind of a deep indication that something is amiss. Why? > it's an argument that was had and decided 20 years ago. Evidently not, if we’re having this debate. > If this is wrong then you can probably assume that lots of other things which are important...are wrong Why? > google why 0-based makes sense by Djikstra Is Djiktra’s opinion so infallible it supercedes the design choices of several successful languages?
- alexeldeib 8y agoI don't hold it against any language, but it certainly breaks with common convention. The number of simple off by one errors I had when I started writing Lua was a bit irritating.
- ModernMech 8y ago> but it certainly breaks with common convention That depends on which circles you run in. If you're a programmer, yeah, it breaks with common convention. If you're a scientist or engineer, not so much. When writing a programming language for scientists and engineers you have a choice: do I stick with programmers' conventions or do I stick with engineers' conventions? I've had the pleasure of teaching both MATLAB and C++ to freshmen engineers. For them, they get off-by-one errors in C++, not in MATLAB.