7 ms·
Me reading the Julia documentation: "Interesting... hmm, don't quite understand that, but moving on... oh that's neat... wait, arrays are 1-indexed, not 0-index
by moron4hire 13y ago
Me reading the Julia documentation: "Interesting... hmm, don't quite understand that, but moving on... oh that's neat... wait, arrays are 1-indexed, not 0-indexed? ABORT!"
EDIT: and I consider this to be all the proof I ever need: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...
- _delirium 13y ago1-indexed arrays are pretty common in languages targeted at scientific/mathematical usage. Also the case in R, Fortran, Matlab, and Mathematica, among others.
- moron4hire 13y ago"This is the way we've always done it" is not a convincing argument.
- steveklabnik 13y ago... for or against 1 or 0 indexed arrays? ;)
- gfodor 13y agoExcept that's not the argument.
- AimHere 13y agoThe argument is more along the lines of 'the users for these systems use 1-based subscripts in their technical literature so we'll make conversion from formula-in-physics-paper to running code easier by having the corresponding data structure match the user's expectation.' 0-based arrays are easier for computer folks who occasionally have to implement the code that translates 'a[i]' into a memory access. 1-based is easier for physicists and mathematicians who were subscripting variables before there were computer implementations to worry about and had a pile of literature already written using that idiom. It's just a clash of conventions.
- dubya 13y agoTo be fair to Fortran, you can easily choose whatever indexing you want. 1 is just the default.
- CatMtKing 13y agoThat's even worse!
- idunning 13y agoA lot of mathematics (and real life, but lets not go there) is written 1-based, which makes it quite a pleasure to translate algorithms into Julia. But I don't think its a big criticism OR selling point really - sometimes its good, sometimes its bad. I personally enjoy it, and I make less indexing errors than I do when writing array/matrix intensive code in C++.
- moron4hire 13y ago"This is the way we've always done it" is not a convincing argument. Dijkstra makes all of the convincing arguments for why 0-based is better than 1-based. I haven't made an indexing-based error in over 10 years, and the only reason I ever had it before was from having to switch back and forth between C and VB6 years ago.
- tristanz 13y agoI'm guessing you don't translate algorithms in scientific papers. The reality is that having one notation for mathematics and programming is a convincing argument to many. More broadly, this indexing thing is trivial. Let's not pretend Dijkstra's paper is proof of anything. At the end of the day his argument is just style: "That is ugly, so for the upper bound we prefer < as in a) and d)" http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831....
- simonster 13y agoOne counterargument is that in natural language, we tend to talk about numbers 2 to 12 and not the interval 2 <= x < 13. The argument for the latter versus the former is probably Dijkstra's weakest: the claim is merely that this makes the empty range "unnatural." The former convention implies one-based indexing for the same reason that the the latter implies zero-based indexing. In Julia, the natural numbers 2, 3, ..., 12 are expressed as 2:12 and the empty range starting at 2 is expressed as 2:1.
- tristanz 13y agoThis is also typically written in algorithms like: N = rows(data) for i in 1:N blah So even though 1:0 may seem not unnatural, it actually reads perfectly in most code.
- silentbicycle 13y agoYou might want to read this, then: http://exple.tive.org/blarg/2013/10/22/citation-needed/ http://exple.tive.org/blarg/2013/10/22/citation-needed/
- mcguire 13y agoAnd, once again, "And that’s the most coherent argument I can find; there are dozens of other arguments for zero-indexing involving 'natural numbers' or 'elegance'[2] or some other unresearched hippie voodoo nonsense that are either wrong or too dumb to rise to the level of wrong." I still believe this is the only time EWD's work has ever been referred to as "unresearched hippie voodoo nonsense". Is this the same Mike Hoye who hacks Zelda?[potato] [potato] http://www.huffingtonpost.com/2012/11/16/mike-hoye-hacks-zelda-vid_n_2140509.html http://www.huffingtonpost.com/2012/11/16/mike-hoye-hacks-zel... [2] http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...
- haberman 13y agoThat article assumes that history is the most important consideration. It doesn't actually evaluate the pros/cons of 0-vs-1-based indexing at all, it just traces the story, as if the path we took to get here is more important than the content of the argument. History can inform the argument, but history does not make the argument. Observing the effects of 0-vs-1-based indexing in existing languages can give us data about the pragmatic effects of either decision. But the precise chain of cause-and-effect of decisions made in the 1960s in an environment where both the hardware and social structures around computing were radically different than they are now is really not that relevant to the question of which approach is better overall. The article is also snide and openly insulting to nearly everybody (including Dijkstra); combined with its lack of a convincing argument, this article does not deserve to be treated as a credible position piece in support of 1-based indexing.
- touristtam 13y agoThanks. Thoroughly enjoyed that article. :)
- RivieraKid 13y ago1-indexing has it's drawbacks (ranges) but it also has benefits. From the projects I've done in Julia my impression was that the net effect of 1-indexing was positive.
- moron4hire 13y agoWhen you say, "1-based is more natural to how humans count", You're really saying, "I'm a child who can't think abstractly, so I probably shouldn't be let anywhere near a computer programming language."
- RivieraKid 13y agoI'm a very good programmer and I agree with him.
- moron4hire 13y agoOT: are you the same RivieraKid who used to post in the Gamedev.net Lounge several years ago?
- RivieraKid 13y agoNo, I'm surprised my nick isn't unique.