9 ms·
Yeah, I agree with your comments about error handling. It’s far from ideal in non-interactive contexts. It’s especially disappointing since you could easily ima
by Q6T46nT668w6i3m 8y ago
Yeah, I agree with your comments about error handling. It’s far from ideal in non-interactive contexts. It’s especially disappointing since you could easily imagine something like Julia replicating Python’s success at transitioning code from interaction (e.g. Jupyter notebook) to production.
I initially defended the choice, but I now agree that 1-based indexing now seems like a poor choice since Julia has become something more than the original mission of a better MATLAB or Octave. It’s a, admittedly, minor tragedy of Julia’s success.
- peatmoss 8y ago> 1-based indexing now seems like a poor choice since Julia has become something more than the original mission of a better MATLAB or Octave. It’s a, admittedly, minor tragedy of Julia’s success. I’m curious as to why this is a problem outside numerical computing. From my perspective, this is consistent with a long history of mathematics dealing with matrices that predates electronic computers. 0-based arrays are popular because C decided to deviate from what had previously been standard in math and in Fortran. Is there a reason other than aesthetic preference and habit that makes 0-based indexes better for computing in non-numerical contexts? I realize both indexing standards are arbitrary and boil down to “that’s the way grandpa did it,” however 1-based indexing grandpa is way older and more entrenched outside computing circles. EDIT: I suppose with Julia it’s not that important, as other commenters have pointed out that you can choose arbitrary indexes.
- kgwgk 8y ago> the technical reason we started counting arrays at zero is that in the mid-1960’s, you could shave a few cycles off of a program’s compilation time on an IBM 7094. The social reason is that we had to save every cycle we could, because if the job didn’t finish fast it might not finish at all and you never know when you’re getting bumped off the hardware because the President of IBM just called and fuck your thesis, it’s yacht-racing time. http://exple.tive.org/blarg/2013/10/22/citation-needed/ http://exple.tive.org/blarg/2013/10/22/citation-needed/
- peatmoss 8y agoWow, I hadn’t seen this before. The history of this feud goes back before C. Thank you for a fascinating read!
- jandrese 8y agoEven Dijkstra weighed in on this: http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF
- e12e 8y agoI've always found this a rather weak argument - he even implies that 2...12 is at least as clear (it being the starting point of the text). I also thought I'd seen a longer text focusing more on the counting/indexing. I still don't see the appeal of "element at zero offset" vs simply "first element". I do agree that < vs <= etc can get messy. But outside of now fairly archaic programming languages I don't see the need. Just use a construct that handles ranges, like "for each element in collection/range/etc". (Or for math, "pattern matching" (or "for n in 1..m").
- disgruntledphd2 8y agoI believe that may be cited in the article (but its not in an obvious place :) )
- danso 8y agoThis was a fantastic (and relevant) read, thank you for sharing it.
- romwell 8y agoThanks for the great article. An unexpected takeaway: Michael Chastain's time-traveling debugging framework, which he had in 1995, and which still reads like sci-fi from the future[1]. Alas, this quote will probably stay relevant for a while: >[We keep] finding programming constructs, ideas and approaches we call part of “modern” programming if we attempt them at all, sitting abandoned in 45-year-old demo code for dead languages. [1]http://lwn.net/1999/0121/a/mec.html http://lwn.net/1999/0121/a/mec.html
- montecarl 8y agoDijkstra has a note on this: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- civility 8y agoZero based arrays are frequently better in a numerical context. Many times when you’re using the index in the computation itself (FFTs for instance), zero based is what you want. For instance, the zeroth frequency (DC) is in the zeroth bin.
- KenoFischer 8y agoWhich is why julia doesn't make any assumptions on how your axes are indexed. If you're working in a numerical domain where 0-indexed arrays, or symmetric arrays about the origin, or arbitrarily other transformed axes make sense, just use those.
- civility 8y agoI understand the argument, but when the default disagrees with your override, there's almost always an impedance mismatch and some pain. It's like being left handed when 99% of the interfaces in the world assume you're right handed. People argue that zero-based is incidental, and that 1-based is the right way because of it's long history in mathematics notation. I would argue that 1-based is incidental, and that zero-based is better most of the time for modern math and computer architectures.
- KenoFischer 8y agoI can understand why you might get the impression, but I'd encourage you to try out julia and see that we're really quite good at using index-agnostic abstractions, so most code doesn't care what your arrays are indexed with. If a certain set of indices make sense in your domain (0-based for FFTs as you say, symmetric indices about the original for image filters, 1-based for just regular lists of things, etc), just use it, and it'll be convenient interactively, but most library code doesn't really think about it that much.
- civility 8y agoI'll (cautiously) take your word that this works transparently when I supply arrays as arguments to a library function. However, what does the library function return to me as arrays it allocates? What if I do an outer product of two arrays with different base indices? Whatever your answer, I suspect it is more cognitive overhead to remember than "always 1 based" or "always 0 based".
- deleted 8y ago[deleted]
- pravus 8y ago0-based indexing has the advantage of easily mapping to memory addresses since the index is an offset from a base address (perhaps multiplied by a unitary per-item length). I personally prefer this since I tend to think about and work with data as an offset from a starting point. 1-based indexing has the advantage of always knowing the length of the array since the index of the last element is this value. You also get "proper" counting numbers as you iterate. I've used both in various languages. Perl lets you define the array index start to be whatever number you wish.
- timholy 8y agoAs noted above, Julia does too. Heck, if you wanted to, in Julia with probably <100 lines of code you could create an array type that only allows prime numbers as indices. And subject to the constraints of the raw calculations needed, it would be as fast as it can be---there is no "extra" performance overhead associated with doing basically whatever you want.
- deleted 8y ago[deleted]
- renox 8y ago> I initially defended the choice, but I now agree that 1-based indexing now seems like a poor choice since Julia has become something more than the original mission of a better MATLAB or Octave. It’s a, admittedly, minor tragedy of Julia’s success Especially since it would have been very easy to 'do it like Ada' and allow any start index by default (I have use Lua and it's really annoying to use an extension language with 1-index when the base language is 0-indexed)
- kleff 8y agoEven Visual Basic (of all things) allowed you to set it with Option Base. Never really understood why its not supported in more languages...
- pjmlp 8y agoBecause due to UNIX's adoption every programming language needed to be like C. Until then Fortran, Lisp, Algol, Pascal, Basic never had any big issue with indexes.
- oxinabox 8y agobecause the whole Option Foo stuff that Visual Basic had, is a hideous global state thing that makes it hard to reason about code without checking for what it's options were set to. Programming languages should not be configurable in that kind of way.
- jebej 8y agoYou can use whatever start index you like: https://docs.julialang.org/en/stable/devdocs/offset-arrays/#man-custom-indices-1 https://docs.julialang.org/en/stable/devdocs/offset-arrays/#... For a pre-baked solution: https://github.com/JuliaArrays/OffsetArrays.jl https://github.com/JuliaArrays/OffsetArrays.jl
- renox 8y agoThe problem is the default behaviour: in Ada you can use whatever you want, in Julia the default is 1-based which is quite controversial.
- ChrisRackauckas 8y agoThis is what 0-based indexing looks like in data analysis: >In order to read a csv in that doesn't have a header and for only certain columns you need to pass params header=None and usecols=[3,6] for the 4th and 7th columns: https://stackoverflow.com/questions/29287224/pandas-read-in-table-without-headers https://stackoverflow.com/questions/29287224/pandas-read-in-... Just reading that hurts me.
- dangom 8y agoThis is very much a non-argument. Call the columns the 4th and 7th is as arbitrary as calling them the 3rd and the 6th. Again, 0-based indexing exists to fit a purpose: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW... In my opinion, reading `a = b[1:n-1]` hurts much more than reading `a = b[:n]`.
- coldtea 8y ago>Call the columns the 4th and 7th is as arbitrary as calling them the 3rd and the 6th. No, that's their ordinal position, and how 8 billion non-programmers would refer them as in any everyday setting. That's also how programmers would refer to them if it wasn't for a historical accident. What's more, that's also how programmers refer to them when they talk between then and not to the machine ("check the 3rd column" not "check the column at the index of 2").
- e12e 8y agoa = b[1..n]?
- DNF2 8y agoThe equivalent of `a = b[:n]` is `a = b[1:n]`. And I don't think you can get around admitting that there is a fundamental ambiguity in the spoken statement "Take a look at the fourth column!" in a zero-based index system. You always need a follow-up question to clarify whether you mean "everyday informal speech fourth" or "zero-index fourth."
- 8y ago
- ScottPJones 8y agoThree years ago, when I found out about Julia (and quickly fell in love with the language), I not happy at all about the 1-based indices and column-major storage, and at the time, a lot of the responses I got were along the lines of "Julia is for mathematicians, and 1-based indexing and column major are just fine for us". Now, Julia is able to have indices with any base that you want, and can handle row-major storage as well (thanks to Tim Holy's great work). Why is anybody concerned about this anymore? Julia can do whatever you want, you shouldn't be stuck with languages that can ONLY do 0-based indexing.