4 ms·
1-based indexing is a non-issue
by stellalo 8y ago
1-based indexing is a non-issue
- ur-whale 8y agoIt most certainly is for the vast number of folks who code in C, C++, Java, Python, etc ... It will for sure hurt adoption.
- weatherlight 8y agoI'm pretty sure if people are willing to adopt a new language, they will be open minded enough to accept 1 indexed arrays.
- ur-whale 8y agoHistory has shown the exact opposite.
- DandyDev 8y agoExamples?
- ur-whale 8y agoYou just have to look at the most popular programming languages on 2018. They're all 0-based (with maybe R as an exception, but R is a niche language. If that's what Julia aims to remain -- their loss). The folks who designed these languages knew how not to alienate their future market.
- cultus 8y agoMatlab is 1-based. That's what the vast majority of scientific programmmers still use. Worrying about 0 vs 1 is just useless bikeshedding, really. I've done lots of index heavy operations in Julia and in Python, and it's easy either way.
- typon 8y agoI think majority of scientific programmers use Python/C/Numpy stack over Matlab
- cultus 8y agoNo, not true at all. Engineering and academia are still solidly Matlab. You have to keep in mind that these people are not programmers, they are used to Matlab, and they don't want to learn another language. It's just a small proportion of new faculty and some grad students that use Python. Statistics is all R.
- goatlover 8y agoIt's not any harder to get used to than using whitespace for blocks in Python, or having to end every damn statement with a semicolon in the C inspired languages.
- ur-whale 8y ago>It's not any harder to get used to than using whitespace for blocks in Python, or having to end every damn statement with a semicolon in the C inspired languages. Strongly disagree. I can move from C to Python without a second thought and rewrite code from one to the other without even thinking. Having to rewrite an algorithm working on multidimensional arrays that was written with 0-based conventions to 1-based conventions and have the resulting code remain readable is a freaking headache.
- SolarNet 8y agoOk, then use the built in Julia features to use any offset you want inside your algorithm's code. Compilers are pretty good about optimizing integer constants.
- ur-whale 8y agoEveryone in this thread seems to believe that 1-based indices is a non-problem because Julia "offers a choice". My reaction: - the default is 1-based, which means the bulk of Julia code will adopt the convention and therefore the vast majority of coders in 2018 will have to do mental gymnastics to understand what the code does. - when I read Julia code, I will never know which convention the code was written with unless I dig to find where that particular flag is set. - passing 0-based arrays to a library routine that expects 1-based stuff, what happens then? - for code that will be 0-based and uses library code that expects 1-based (assuming that's possible without paying copying overhead) will force the code to mentally switch between the two modes. Ugh. In short: offering is a choice is maybe even worse than enforcing 1-based.
- int_19h 8y ago
- pjmlp 8y agoSome of those folks started when Fortran, Basic, Clipper, Pascal, Modula-2, Ada were relevant. 1 based indexes were just fine.
- kazinator 8y agoVectors are zero based in Common Lisp; the 1960 Lisp 1 manual describes arrays; they are zero based. Zero based is much more sane. If the array is regarded as being made up of larger groups of elements, say groups of 8, then ⌊index/8⌋ gives us the group and group x 8 gives us the base element of group. Not so if index is one-based. Zero based multi-dimensional coordinates are easy to convert to a flat address. E.g. 3D case: just ABz + By + x. Imagine distances were one based (so that either 1 m or 1 km means no displacement), and then trying to convert a given distance between m and km. Yikes! Music intervals are one-based, to their great detriment. We end up with a "rule of nine" for interval inversion and that comes from the octave of the diatonic scale having seven notes! One-based indexing is okay when the indices don't have a strong numeric meaning (beyond basic successor/predecessor relationships), or none at all (basically are symbolic and could be replaced by any set that can be enumerated by the natural numbers). As soon as the index domain is involved in displacement calculations that feature multiplication and division, anything but zero based is disadvantaged.
- pjmlp 8y agoI also have read Dijkstra, it doesn't mean I agree with everything he wrote. In Algol based languages indexes are customizable, I don't remember ever writing array [0..9] of Integer instead of array [1..10] of Integer. C, C++ and their descendants took over and I just had to adapt.
- stellalo 8y agoI haven’t, so far, encountered a single occasion in which I would need to manually flatten-deflatten indices: Julia has multidimensional arrays of any dimension N, and you can access their content in a linear fashion without any effort (simply provide one index instead of N)
- BeetleB 8y ago>It will for sure hurt adoption. Reminds me of the complaints my friends had about Linux when I first showed them a fantastic window manager. "This will never get anywhere. It has no Start button." If I were in a team that refused a language just because it is 1 based indexing, I would really worry about the abilities of the team.
- dnautics 8y agoI started using elixir/erlang, which basically doesn't have indexing, ever. It's been a joy.
- stellalo 8y agoI love C and I was myself suspicious when I first tried Julia. I ended up being perfectly able to reason in terms of 1-based indices and right-inclusive ranges. I’m sure I’m no special kid :-)