4 ms·
Personally, I find it annoying considering it's just based on convention from other math software. Otherwise, an amazing language.
by ZeroCool2u 8y ago
Personally, I find it annoying considering it's just based on convention from other math software. Otherwise, an amazing language.
- kbenson 8y agoWhereas 0 based indexing is based on convention from other languages where it arguably made more sense because it was just a convenience over pointer arithmetic. What reason other than convention is there for 0 based array indexing in any any language where an array isn't just a memory location and the index a calculation of type-size times index bytes?
- murderfs 8y agoEdsger Dijkstra on why numbering should start at zero: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- kbenson 8y agoWhich is a valid argument for numbering starting at zero, but not just for programming languages, but in general and including human spoken languages. The common counter-argument is "People don't generally think that way unless trained to do so". Like many things in life, often convention and momentum often trump reasoned argument. In general, much of what's chosen for language design is influenced to some degree by convention. This is a valid design choice, because you're maximizing use of existing domain knowledge of your audience. In this specific case, I would argue that since in many languages where an array isn't a small shim over memory management (Ruby, Python, Perl, JS, etc) where easing user friendliness is at a premium over performance, 1 based array indexing would make better sense... if most people adopting those languages weren't already fairly well acquainted with 0 based indexing from CS programs or exposure to other languages (and it wasn't a simple concept to understand). Since many new users are familiar with it, and it is easy to understand, it's simple to just go with what some percentage of people already know, so convention wins out.
- int_19h 8y agoThere are many rebuttals to this claim by Dijkstra, too.
- superlopuh 8y agoFunny how the argument about veering into the unnatural numbers is voided by a Maybe type.
- samatman 8y agoThe One True Wiki has a fairly complete discussion of this question: http://wiki.c2.com/?WhyNumberingShouldStartAtZero http://wiki.c2.com/?WhyNumberingShouldStartAtZero What I find most persuasive is that 0 based indexing brings measurement into accord with enumeration.
- xiphias2 8y agoMaybe this is a stupid idea, but at this point the economy is tied to 0-based indexing so much, that I would rather get math moved to 0-based indexing, than computing to 1-based indexing. Being able to easily port code between languages (and math articles) is important, when there's no clear winner, I like consistency.
- Certhas 8y agoGood luck with that. The 0-based indexing is non-existent outside of programming. No one who doesn't do pointer arithmetic would come up with it. In mathematics 1...N is a perfectly good notation. Julia expresses the same idea with 1:N. This is consistent with spoken language (1 denotes the 1st element). Consistency, if anything, would not come down in favor of the software engineering choice here.
- xiphias2 8y agoA lot of new very important papers in i.e. machine learning, quantitative finance come _after_ being implemented in computer code. I just looked at some, and they already seem to use 0 index for the initial states / base layer... here's just one example, where 0 and 1 based indexing is mixed, but I see it everywhere: https://arxiv.org/pdf/1804.02717.pdf https://arxiv.org/pdf/1804.02717.pdf
- Zanni 8y agoExcept European hotels, where the first floor is one up from the ground floor, making floor number effectively zero-based.
- xiphias2 8y agoIt's bad for me too, also missing some other features of Ruby (for example or, and keywords; ,,if'' keyword as a modifier, using blocks for passing a function as a parameter for functions), but there were some great surprises: the windows support seams superior to Ruby's, where I get a lot of compile errors; of course more/better math libraries.
- Certhas 8y agoWhen I started Julia I was annoyed by it. Then I realized that 90% of my mental gymnastics with indices got simplified. Explaining indexing to newbies is now immediate where before it took a slide, several examples, and a clever picture. Slicing is also more natural: "1:3 picks out index 1, 2 and 3, which are the first, second and third element of the array." Instead of the python version of "0:4 picks out index 0, 1 and 2, which are the first, second and third element of the array."
- petre 8y agoLess off by one errors for one.
- saghm 8y ago> "0:4 picks out index 0, 1 and 2, which are the first, second and third element of the array." I don't think that's right? It should pick out four things, not three. Of course, you could argue that getting that wrong proves your point! I personally still prefer 0-indexing, but I definitely agree with you that having an exclusive upper bound is confusing.
- Certhas 8y agoYou're right of course. Not intentional. 0:3 picks out index 0, 1, 2. So 1:3 picks out the second and third element, which are indexed by 1 and 2 respectively. My guess is that what one prefers probably depends entirely on the data structures one works with most....
- shele 8y agoI like how you got it wrong, proving your point.