16 ms·
It really comes down to a choice between a machine-focused (0) or human-focused (1) approach. The 0 makes a lot of sense in a C pointer world where memcpy and
by hougaard 4y ago
It really comes down to a choice between a machine-focused (0) or human-focused (1) approach.
The 0 makes a lot of sense in a C pointer world where memcpy and other alike functions can be written very thight.
The 1 makes a lot of sense in a human world, when we count, we start at 1, we talk about the "1st", counting on finger starts with 1, etc.
I once were at a Lua (1 indexed language) conference where this was discussed, and Luis started explaining why Lua was 1-index with this sentence: "The 1st argument ...." :)
- kazinator 4y agoIs it machine-focused that we can convert a distance of 1.5 m to 150 cm just by multiplying by 100? Maybe distances should be human-focused, so that no displacement is equivalently expressed as 1 cm, 1 m, 1 km, ... Then converting a distance d from m to cm is (d - 1) x 100 + 1.
- hougaard 4y ago... but if you have something that's 150cm, that's not 151cm, that's 150cm?
- qsort 4y agoI don't think 1-based arrays are better notation, even completely ignoring that code has to run on a machine. 99% of the times, the correct approach is to use iterators. When you really need indices (and you almost never do), 0 is more practical, because it matches the "including start, not including end" convention.
- randomdata 4y ago> when we count, we start at 1, we talk about the "1st" Although often with an implicit zero. Under typical North American culture, your 1st birthday, for example, is more accurately the first anniversary of your birthday. Your birth is zero indexed.
- atwood22 4y agoNo, birthdays are 1 indexed. Your Nth birthday is the day you turn N years old. When you're 1 year old, you've been alive for 1 year, not 2 years.
- brianzelip 4y agoSo how old is a not-yet-1-year old?
- atwood22 4y agoN days or N months depending on how old the baby is.
- randomdata 4y agoAnd it turns out that 0 days, 0 months is 0 years.
- rcoveson 4y agoAnd before an hour has even passed, we'd probably say "minutes old" or perhaps "not even an hour/day old", all to avoid saying "zero days/months/years old". But some might still say zero days old, and they'd be both understood and correct (at least logically if not stylistically). That's the "implicit zero" everybody is talking about. We avoid saying it, but that's just a convention of communcation. Logically it's there. You're zero days old before you're one day old.
- nomel 4y agoElapsed time timers start at 0. Time is continuous. The elapsed time being “out of the womb”, that we call “age”, starts near 0. Five minutes after birth, the baby has been in the world for, or it’s age is, five minutes. If someone asked how old a new baby is you could hear “3 weeks”. Another definition might be from conception. But birth being “one year old” is illogical. The sperm didn’t even exist yet, one year before birth.
- xxs 4y ago
- croes 4y agoIf you think of the index as an offset you would start with 0. BTW on which level is the 1st floor?
- t_mann 4y ago> BTW on which level is the 1st floor? in Europe or in the US?
- ethbr0 4y agoDoes Europe has a zero floor? Please tell me Europe zero-indexes their stories!
- t_mann 4y agoThey do, it's called the ground floor.
- espadrine 4y agoIn France, it is called the rez-de-chaussée. The “premier étage” (literally translated as “first floor”) is what the US calls the second floor.
- mananaysiempre 4y agoA particularly topographically challenged building in Paris has exits to two enclosing streets end up on different floors. The elevator is numbered -2, -1, rez-de-rue [exit north], rez-de-chaussée [exit south], 1, 2, ... .
- 988747 4y agoDon't know French, but I wonder if the meaning of "etage" is similar to Polish "piętro", which literaly means something like "elevation". So, basically in Polish we have a specific word for ground level, and then we count how much elevated above the the ground the current level is. That's why "1st floor" is the one "elevated one level above the ground". In English you count "floors" and floor is a usable, hard surface on which you can put something, like a chair. That's why a floor on the ground level is treated the same as the floor above it - it is equally good on accommodating chairs, beds, and other stuff.
- numlock86 4y ago> It really comes down to a choice between a machine-focused (0) or human-focused (1) approach. Just think of 0-based as offset-based and 1-based as index-based. Both are intuitive just like that. I never get why people arguing over this bring pointers and memory (or anything computer related) to the table. No normal person is going to understand that, but everyone understands that if you don't move at all (0 offset) you stay at the first (index 1) item. Add one and ... you get the point.
- kazinator 4y agoOffset-based lets you refer to an abstract location that is after the last element without resorting to n + 1. [ ] [ ] [ ] ... [ ] 0 1 2 3 n-1 n We can regard this n as a "virtual zero", and then make it possible to index the n - 1 element also indexable as just -1. The index -n then aliases to 0.
- deleted 4y ago[deleted]
- Joker_vD 4y agoAnd then the counting niceties come along: those perennial +1 mistakes are caused by the fact that, e.g. 4 and 5 are two numbers but they are only one apart.
- lupire 4y ago"ordinal" is preferred to "index", as "index" doesn't naturally suggest starting at "1", or even restricting the key to integers. "Ordinal" starts from 1, everyone agrees (except mathematicians, of course :-) ).
- pb7 4y agoAsk 100 random people on the street and I'd be surprised if even 1 knew the definition of "ordinal". It's an uncommon word.
- LudwigNagasena 4y ago
- kazinator 4y ago> when we count, we start at 1 That is false; counting begins by initializing an accumulator to zero. When you register the first item, the count jumps from 0 to 1.
- goatlover 4y agoWho sets an accumulator to zero and then adds one in everyday language?
- kazinator 4y agoFor instance, someone who makes a fist with zero extended fingers before counting. Or someone who simply becomes motivated to count something, without making any utterances or gestures to that effect. The motivation is followed by the persistent awareness that nothing has been counted yet, which then changes to 1.
- pvinis 4y agoNot saying "zero" doesn't mean we don't mean it. All counting starts with 0. We just say "one" out loud as the first number. We probably should say "zero" too, but why say a word when you can say no words?
- goatlover 4y agoOr we just start counting with 1, since 1 is the first number we start with. Do small kids start with a concept of zero and then adding one to it, or do they just start at one?
- kazinator 4y agoIf you start at 1, how do you answer the question "how many apples are in the basket", when the basket is empty? Or do you believe that the answer "none" or "zero" is then given without the activity of counting having taken place? What do we call the meta-activity then: the procedure that results either in the "empty" answer or "one", "two"? Whatever that activity is called, it starts with a concept of zero. Let's call that activity "quanting". Quanting starts with a motivation to enumerate items, and an initially empty result. When no items are present, quanting terminates, reporting that zero/nothing/none result. Otherwise quanting branches into a subprocedure called counting, and that begins at 1.
- kazinator 4y agoIn Western music theory, intervals are one based. No pitch change is "unison"; one diatonic step is a "major second" and so on. As a result of this silly state of affairs, an octave occurs every 7 notes, even though the root "oct" means eight. Furthermore, a "rule of nines" is needed to invert an interval: e.g. inversion of minor 3rd is a major 6th (exchange major/minor, subtract from 9).
- OscarCunningham 4y agoAnd addition also gets broken. Like a third plus a fourth is a sixth.
- oh_my_goodness 4y agoTrue, and it's a great example of how this whole drama is about a practical trade-off, not about a unique Right Answer. If you play piano, the second is the second finger; the fifth is the fifth finger, and it all makes sense. No problem. On the other hand trying to actually count that way (two thirds make a fifth and so forth) is maddening.
- qu4z-2 4y agoClearly the solution is we need to start numbering fingers from 0.
- oh_my_goodness 4y agoMaybe that would do it. The only problem is that I'd have four fingers on each hand.
- kazinator 4y agoNo, just use subtraction for the intervals. Third finger minus first finger = 3 - 1 = 2. The floors of a building might start at 1, but you go up 1 flight of stairs from the 5th to the 6th floor, not two.
- zajio1am 4y ago> The 1 makes a lot of sense in a human world, when we count, we start at 1, we talk about the "1st", counting on finger starts with 1, etc. It is more like counting from 1 is just a leftover from times where zero was not commonly considered as number. Once one have zero, it makes sense to use it as an initial ordinal (see e.g. set theory, where zero is both initial ordinal and initial cardinal number, way before computers). Another example is time and date, we start counting of days from 1, but counting of hours (at least in 24-hour notation) and minutes from 0. > Luis started explaining why Lua was 1-index with this sentence: "The 1st argument ...." Note that for spoken language, it is "The first argument ..." and 'first' is etymologically unrelated to 'one', but related to 'foremost', 'front', so it make sense to use 'first' for the initial item in the sequence even when using counting from 0.
- steadicat 4y agoWhen talking about discrete things, 0 has a specific meaning: it is the absence of things. It does not make sense to count the 'first' element as the 0th. When you encounter the 'first' element, how many elements do you have? 1. This is of course different for continuous quantities. When counting seconds, for example, we should absolutely start from 0.
- bentcorner 4y ago> The 1 makes a lot of sense in a human world, when we count, we start at 1 As a kid I learned "one one-thousand, two one-thousand, three one-thousand" when counting time out loud, but at some point I realized this was incorrect. The prefix is the start of the nth second but it isn't complete yet, so for example stopping in the middle of saying "two one-thousand" you actually haven't reached two seconds yet. My fix was to move the prefix to the end, so I say "one-thousand one, one-thousand two, one-thousand three". In retrospect maybe I should have used "zero one-thousand, one one-thousand, two one-thousand".
- 8note 4y agoNone one-thousand, one one-thousand, two etc Doesnt sound half bad
- ziml77 4y agoI don't think it's necessary incorrect to start at one there. If someone asks you to count out 3 seconds, you're going to say "one one-thousand, two one-thousand, three one-thousand" and only at the end of the "three one-thousand" will you have considered the 3 seconds to have actually elapsed. Basically you're already accounting for the time it's taking you to say it. Which to me seems better because if you do it the other way because it gives a better heads up as to when that second has been reached.
- HarHarVeryFunny 4y agoYes, but "human-focused" 1-based indexing comes at a cost since at the end of the day the CPU has to add (index * element-size) to the array base address to get the address of the indexed element. With a 1-based index there's additional overhead in either having to subtract 1 from the index or to have a wasted "element 0" to avoid the need to do that.
- copperx 4y agoI assure you, that if we counted from zero, there would be an instruction to add and multiply in the same number of cycles as a multiply.
- HarHarVeryFunny 4y agoThat's not possible - the subtract and multiply need to be consecutive (adjust index before multiply by element size), so even if it was a single instruction it would still take longer than a multiply that didn't have to wait for a preceding subtraction. The only way to avoid the speed penalty would be either to have a wasted element at offset 0, or to maintain the array base address as (address - (1 * element-size)) to avoid having to subtract 1 from the index when accessing. In the latter case for dynamically allocated arrays the code would still have to do a subtraction to adjust the pointer returned by the memory allocator, but at least that would be a 1-time penalty rather than per-element-access. Of course this is supposing a high level language where an array is abstraction, not one explicity aliased to a chunk of memory such as C where an array and a pointer to it's first element are interchangeable.
- copperx 4y agoThat goes against my intuition. Multiplication in hardware to this day relies on addition. Is one adder going to add an extra cycle? Or would that time be amortized? Take a look at slides 45-46 here. https://acg.cis.upenn.edu/milom/cis371-Spring08/lectures/04_integer.pdf https://acg.cis.upenn.edu/milom/cis371-Spring08/lectures/04_... Do you know the answer to that question? (I don't, but if someone does, it will settle this issue).
- co_dh 4y agoHuman makes a lot of inconsistent thing: We usually think the 1st floor, and the basement as 1st underground floor ( -1), but the floor jumps from 1 to -1! Also, the time jump from 11AM to 12PM to 1PM! So I think more human friendly sometimes means more confusing.
- copperx 4y agoIt's like English pronunciation, there's little logic. I gave up finding logic in these things at an early age, and resorted to memorizing everything instead.
- luispauloml 4y agoThat's true. But as for floor numbering, specifically, it depends on the country: some places have a "ground floor" between the 1st underground floor and the 1st "above ground" floor.
- BorisTheBrave 4y agoIn Europe, the floor level with the ground is called "ground" or "0".
- jcelerier 4y agoAt which number starts the first centimeter on a ruler ?
- xxs 4y agoI have used 1 based in basic/pascal and 0 based (well in pretty much everything), 0 based effectively no off-by one mistakes. 1 based - common. Most idioms - incl. forward and reverse iterations work better, and are easier to remember with inclusive/exclusive pattern Other than that - binary AND and power of 2 sized arrays are the backbone of any hashtable. Overall modulus (binary AND) is actually useful.
- bregma 4y agoAh, yes. Cardinal numbers and ordinal numbers both end in the word "numbers" so they're the same thing. No need to distinguish between having three apples and having the third apple.
- Old_Thrashbarg 4y agoIf you ask most people to just label their apples, they'd call the first one "1", and so on. Very few people would say, "please pass me apple #0".
- goatlover 4y agoAnd if someone did say that to me, I would pass them no apple, since that's how we use everyday language. And if I knew they were a programmer, I'd first ask them in which programming language they'd wish me to pass the apple.
- Old_Thrashbarg 4y agoI believe there's a powerful status quo bias. Doing the reversal test, if programming languages had all been 1-indexed, then I doubt we'd hear much from people, in 2022, saying "I think the first element should be 0, and the second 1".
- Aardwolf 4y ago> human-focused (1) approach. TBH humans would have been better of if we were 0-based, it's just a convention. And we have the confusing language where "20th century" means 1900's. If we wanted to bring the 1-indexing we use in language to the fullest extent here to fix that particular issue, time counting would have to start at 1111. Except that won't work once reaching 5-digit years. If we would start with "zeroeth" instead of "1st", then this would have solved itself and 20th century would mean 20xx's.
- airstrike 4y ago> where "20th century" means 1900's to this day I can't seem to be able to explain to people that Jan 1 2000 was NOT the start of the new millennium, but rather Jan 1 2001 https://www.latimes.com/archives/la-xpm-2000-dec-26-mn-4810-story.html https://www.latimes.com/archives/la-xpm-2000-dec-26-mn-4810-...
- analog31 4y agoI always thought of the machine focus being that the location of the first element was the location of the array plus zero.
- Aardwolf 4y ago> human-focused (1) approach. TBH humans would have been better of if we were 0-based, it's just a convention. And we have the confusing language where "20th century" means 1900's. If we wanted to bring the 1-indexing we use in language to the fullest extent here to fix that particular issue, time counting would have to start at 1111. Except that won't work once reaching 5-digit years. If we would start with "zeroeth" instead of "1st", then this would have solved itself and 20th century would mean 20xx's. I especially don't understand why mathematicians use 1-based indexing (for matrix rows/columns etc...). Like programmers, they should see the advantages of starting at 0 (e.g. the coordinates of subdividing into block matrices are simpler if starting at 0). Mathematicians do start at 0 for the origin of plots, after all.
- OscarCunningham 4y ago> If we wanted to bring the 1-indexing we use in language to the fullest extent here to fix that particular issue, time counting would have to start at 1111. That's funny, but there's actually an elegant way to do it called Bijective numeration (https://en.wikipedia.org/wiki/Bijective_numeration https://en.wikipedia.org/wiki/Bijective_numeration). We're currently living in the 1A22th year.
- tromp 4y ago> when we count, we start at 1 If I ask you to count the number of red balls in a bag with only 3 yellow balls, then the initial count in your head is 0, you inspect the balls one by one, never encountering a red ball, and thus never incrementing the count. And then you pronounce your final count of 0. So that's counting starting from 0. What you call "starting at 1" is not so much the start as it is the first increment, which need not arise.
- thayne 4y agoThere are a lot of cases where a zero index makes sense. In physics and math there are cases where you start the index at 0 and others where you start at 1. And even some where you start at -1. Which you use depends on what is most convenient for the problem at hand.
- kevin_thibedeau 4y agoIt has nothing to do with pointers and everything to do with basic computer arithmetic. You can constrain the range of an integer with a bitwise AND operation providing a cheap modulus by power of two. In this regime, zero-based indexing is the natural result. You have to make an adjustment for 1-based. There are whole host of other operations that are simpler with 0-based indexing. The problem it that most people, even programmers, don't understand how computer arithmetic works and have fantasies of mathematical number lines that the hardware only partially simulates. You see this consistently in the post-Java crowd who think that unsigned integers are some sort of unholy aberration because the languages they've grown up went further to maintain the fictional number line semantics.