3 ms·
Zero based indexing? I find it not too bad to switch between languages that use zero & one based indexing.
by throwaway7645 9y ago
Zero based indexing? I find it not too bad to switch between languages that use zero & one based indexing.
- Bromskloss 9y agoIt's not that one is incapable of doing it. It's that one way is wrong and the other is right!
- goatlover 9y agoRight, so zero-based is wrong unless one is using a language close to assembly.
- Bromskloss 9y agoWhich one is "right" and which one is "wrong" (those are strong words I chose somewhat tongue-in-cheek) is a matter of opinion. I have my opinion, and that is that zero is the proper number to start enumerations on, not just in programming, but for everything.
- goatlover 9y agoSure, but why would zero be the proper number to start counting at outside of zero-based programming languages? Everyone starts counting objects at 1. Zero means an absence of objects to count or list. I count that there are 7 cars in the lot. The first one is 1. If there were 0 cars, I would not have any to enumerate over. If I make a list, I always number the first one as 1 (or A). If there was nothing on my list, I would have nothing (0) to number. Word processors start list numbering at 1. Printers number the first page as 1. Kids are taught to count starting with one, using one finger. I feel like this is only an argument because we have zero-based indexing in mainstream programming languages, although maybe there are some mathematicians who think otherwise?
- Bromskloss 9y ago> Sure, but why would zero be the proper number to start counting at outside of zero-based programming languages? I don't take programming languages as a reference point. It's the other way around. I try to figure out what the most natural, principled, and elegant way would be, and I would base my programming language on that, if I were to design one. > Zero means an absence of objects to count or list. I count that there are 7 cars in the lot. The first one is 1. If there were 0 cars, I would not have any to enumerate over. If I make a list, I always number the first one as 1 (or A). If there was nothing on my list, I would have nothing (0) to number. We should distinguish between two uses of the natural numbers, I think: 0. _Ordinal numbers_, for assigning labels to things. "This is car 3." 1. _Cardinal numbers_, for saying how many things there are. "There are 7 cars." The relationship between the two would be that the number of cars is the number that is next in line when you have called out the indices (0, 1, 2, 3, 4, 5, 6) of all the cars. > Word processors start list numbering at 1. Printers number the first page as 1. Kids are taught to count starting with one, using one finger. I feel like this is only an argument because we have zero-based indexing in mainstream programming languages What is the most common isn't what determines, for me, what is the most proper. I will play along and use 1-based indexing when I have too, but in my heart I know how I think it should _really_ be. > maybe there are some mathematicians who think otherwise? Yes, though starting numberings on 1 is still common (maybe the most common). Zero is at least recognised as a natural number nowadays. Historically, this wasn't the case. Apparently, Peano started on 1 in his axioms for the natural numbers [0], and zero, as far as I understand, hardly had the status of being a number at all during much of Greek and Roman antiquity [1]. [0] https://en.wikipedia.org/wiki/Peano_axioms#Formulation https://en.wikipedia.org/wiki/Peano_axioms#Formulation [1] https://en.wikipedia.org/wiki/0#Classical_antiquity https://en.wikipedia.org/wiki/0#Classical_antiquity
- goatlover 9y ago> The relationship between the two would be that the number of cars is the number that is next in line when you have called out the indices (0, 1, 2, 3, 4, 5, 6) of all the cars. But who thinks that way? I just see 7 cars, not an indexed listing. And anyway, the 0 indexed car doesn't exist.
- rrock 9y agoNo, zero is the right number to start an offset, not an enumeration. No one starts counting from zero in real life.
- Bromskloss 9y ago> No one starts counting from zero in real life. The question for me is what one _should_ do, not what is usually done.
- btschaegg 9y agoThe argument of zero vs one-based offset is not very new, and since there's a record of musings from Dijkstra on the topic[1], I feel obliged to mention it. Note: Although I'd side with EWD on this one (for now, at least), I don't intend to reference it as an "appeal to authority", but as an example of someone producing a reasonable, properly worded and thought-through argument on the topic, which I've not really seen since. I'd be very interested in what similar arguments would look like from the other perspective. If someone would like to convince me, feel free give me a link to some reasoning :) Also: I personally find "it's always been like this" to be a terrible argument in either case. Those are the reason we weren't able to standardize for one system of units, for example. In the Swiss army, there's a saying that is used to explain the various idiotic decisions and the bogus explications thereof a soldier has to endure: Ist so weil ist so, bleibt so weil war so. Liberally translated: Things are like that because they are like that. All stays that way because it was that way. [1]: EWD831, https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
- goatlover 9y agoI don't have problems with it, but I also never had an issue with Python's whitespace, or languages without semicolons, or languages which prefer to use begin/end blocks. I don't get why it's a big deal. The one exception to that is when switching between languages. Sometimes one forgets which language one is in and a syntax error will result. Like using the dot operator to concatenate strings in Python or leaving semicolons off the end of PHP statements.