5 ms·
> Especially the deeply embedded one-based indexing That's already reason enough for me not to use it. One based indexing caused me so many headaches in the pa
by mschuetz 8y ago
> Especially the deeply embedded one-based indexing
That's already reason enough for me not to use it. One based indexing caused me so many headaches in the past in Mathematica...
- saagarjha 8y agoOne-based indexing doesn’t really make sense if you’re not using pointer+offset array indexing. So the only problem I see here is that you can’t directly port code that deals with arrays over from different languages, which is what you should be doing anyways because tables are not arrays.
- mschuetz 8y agoOne based indexing isn't just about getting used to it, it makes lots of things a nightmare. Like index-math that involves the modulo operator, which will result in zero values, which are invalid for 1-based indexing. Or turning a 2D or 3D index into a 1D index, which now requires completely unnecessary additions or subtractions of 1s. And other index magic that I frequently need for computer graphics and number crunching.
- ur-whale 8y agoI wholeheartedly agree. As a matter of fact, I had the exact same argument in a Julia thread (modulos don't work, polynomial accesses don't work). It honked off a whole bunch of people who've never had to do any of these things for a living and therefore considered them edge cases. Additionally, for LUA, being one-based while trying to claim it's the scripting language for C inter-operability is quite preposterous.
- coldtea 8y ago>As a matter of fact, I had the exact same argument in a Julia thread (modulos don't work, polynomial accesses don't work). In the same ways that simple for loops "don't work" because we need to e.g. check if i < length - 1 to know if we're at the last element...
- mschuetz 8y agoWhich is easy and legible if you do it. With modulo and 1 based indices, it gets messy.
- jlarcombe 8y agoYeah why on earth did they do this? It's such a pain. I can't think of a reason why it would be a good idea, except perhaps "non-programmers don't expect to count from zero" but surely it's easier to overcome that than overcome all the little problems that stem from starting indices from 1.
- ModernMech 8y ago> but surely it's easier to overcome that than overcome all the little problems that stem from starting indices from 1. It's not. You're asking new learners to overcome a great deal of intuition when already attempting to learn a mind-bending thing like programming. I've taught C++ and Matlab side by side to freshmen in university. They learn C++ first and encounter all kinds of off-by-one errors the compiler doesn't help them catch. When they get to Matlab, the universal sentiment I've found is "wow, this makes so much more sense" For new learners, 0 indexing seems like such a pointless frustration with an obvious solution. It can be a needless roadblock for people otherwise excited to learn.
- blt 8y agoAn underappreciated facet of matlab that makes it mistake-resistant: by default, all parameters are passed by value. Thus, all functions are pure / referentially transparent at their interface, even if mutation is used internally. This combination is the easiest for beginners to learn, IMO.
- ufo 8y agoWhen Lua was originally created its primary audience were engineers used to FORTRAN's 1-based indexing.
- tbirdz 8y agoI'm no fan of 1-based indexing either, but for these use cases it's not that hard to add a function to adjust the indexing for you. For example: a mod1() function that will adjust mod to 1-based indexing, and then using mod1 instead of %. Same goes for indexing, you could write some functions like idx2(x, y, width, height), idx3(x, y, z, width, height, depth) that would compute the 1d index for you instead of using y*width+x (or the equivalent form adjusted for 1-based indexing) like you normally would.