10 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 ...." :)
- 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".
- 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.
- anigbrowl 4y agoNo. Your age is 1-indexed. It's a 'birthday' in English and German ('geburstag'); in French it's 'anniversaire', and so on. But pretty much everyone indexes age from 1. The fact of your birth is the transition from (legal) non-existence to existence, the equivalent of a dimensionless point.
- wruza 4y agoAge is definitely 0-indexed - a newborn and exactly 1 year old differ by a year. People also count months during the first year, which is still 0 years old. As in 00:xx is the first hour, and 01:xx is the second. If you're 30 years old, it's your 31st year of life now. But gregorian epoch itself is 1-based. 1AD (0001-01-01) goes right after 1BC (-0001-12-31). There was no 0000-mm-dd. That's why 3rd "millenium" and 21st century started at 2001-01-01 and not at 2000-01-01. YYYY means not how many whole years already passed, but which incomplete year goes right now. On the other hand, your age means "whole years passed since birth [plus maybe a few months]".
- bmacho 4y agoAge is not indexed. And the birthdays are definitely 1 indexed: you denote your first birthday with 1, and not with 0, and so on. You don't denote any birthdays of yours with 0. You may denote something else with it, but birthdays[0] gives an out of range exception. (Especially true in French, where birthdays are called anniversaire, but in English too.)
- 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.
- randomdata 4y agoThe moment you are born you are 0 years old (or perhaps 0.75 years old, but we don't usually recognize that). We count from zero in this case, at least implicitly. In some cultures you are considered 1 the moment you are born, so the zero indexing isn't universal here, but typical in North America as noted earlier.
- atwood22 4y agoNo, we don't count from 0. That's like saying we start counting a baker's cup from 0 because you can have half a cup.
- randomdata 4y agoIf we (speaking as a North American) count from 1, does that mean other cultures (e.g. Korean) count from 2?
- atwood22 4y agoNo, it just means we have a different notion of what a year is in regards to age. Similar to how different cultures can use different units of measurement for length, mass, etc.
- randomdata 4y agoYes, exactly. One of which carries an implicit zero indexing. The date of birth doesn't disappear just because you decided to use a different measuring device.
- 4y ago
- hougaard 4y agoYeah age is confusing even for non-computer-folks :) If you have 4 classes in school today, you would never talk about the 1st class as number 0, the last one is the 4th, not the 3rd.
- randomdata 4y agoAlthough, there is a fifth state in your example: When you are not in class. Which is different to an empty set that implies nothingness. When it comes to age, 0 being birth works well because there is truly is nothingness (from your perspective) before birth. When counting from 1 there is suggestion that there are variables that aren't worth speaking of because they are obvious.
- goatlover 4y agoAssuming there is nothingness for the fetus the entire nine months in the womb. For that matter, I can't recall being younger than four, so it's all nothingness before then.
- randomdata 4y agoNot really. Perspective isn't scientific and often cultural. Koreans, for example, famously have a different take and use a different counting systems to accommodate. I am assuming that the reader is biased towards the average HN user. That won't always work for everyone who will come across my comment, but close enough for an unpaid contribution. I'm not about to write a novel to make sure I catch every edge case.
- deleted 4y ago[deleted]
- ethbr0 4y agoIt's fundamentally a distinction between end-index and start-index. Most human counting uses end-index. I.e. "1" is after 1-thing (has passed, is physically obtained, etc.). Most computer counting uses start-index + length, for efficiency and to better generalize. I.e. "1" is at the memory address immediately before the "1"st item. Which ultimately creates the "0 index is 1st thing" linguistic confusion. PS: Also, language predates computers by a few years, and the concept of zero is hard.
- smegsicle 4y agogood take! i think a more accurate and complete idea is that humans refer to a thing in its entirety, with things being lined up and scanned in order as only a potential convenience if you ask someone to identify an object, they'll point to the middle (or center of the most important component) of the object, not to the 'start' or 'end' of it in their field of vision.. that said, the human perspective is subtle and convenient in completely different ways to how a computer manages memory, and this 'end-index' idea seems like a useful way to map the human whole-object perspective to a linear memory-index perspective
- ethbr0 4y agoThey may point to the middle, but that's not a reference to half an object. ;) The assumption is that the thing is its entirety, as you said. Hypothetically, I imagine an array index reference, in human terms, would be communicated as "this thing starts here" or "this is the beginning of this thing." Which isn't a concept or phrasing we have much occasion to use, other than for routes or long length-measured objects?
- Stratoscope 4y agoRulers too. A ruler starts at 0, not 1.
- dividuum 4y agoNot all of them do: https://twitter.com/blinry/status/1550920690529968128 https://twitter.com/blinry/status/1550920690529968128 %)
- Stratoscope 4y agoNice! I want a Lua ruler now.
- anigbrowl 4y agoThat's because it's dimensional. How long is the shortest possible ruler?
- dalmo3 4y ago1 planck length, and... It starts - and ends - at 1?
- Tagbert 4y agoBirthdays are anniversaries. Anniversaries are annual activities when we celebrate/honor past events. They do not include the event itself. The first anniversary is 1 year after the initial event.
- randomdata 4y ago> Birthdays are anniversaries. Indeed they are, which is why I literally said so in the previous comment. Did you forget to finish reading it? > They do not include the event itself. That is true because the event itself is implied information. There is no value in speaking of it. If you stand before us, we can be certain that you had a day of birth (your 0th anniversary). We don't necessarily know how many times you've gone around the sun following that, however, so that is where we find value in communicating additional information. If you were counting apples, there is the state where you have no apples (index 0), the state where you have one apple (index 1), the state where you have two apples (index 2), etc. When counting you don't need to worry about index 0 because the no apple state is naturally implied. It only becomes interesting and worthy of communication when you have at least one apple to speak of, thus you start at 1. The state found at index 0 is still implicitly there, though.
- lupire 4y agoIf I care about apples (for my lunch, or my store), I care about the difference between having 0 of them and not having bothered to count yet. 0!=null
- randomdata 4y agoIf no apples is the unusual state, like you expected to find an apple in your lunchbox but someone ate it without your knowledge, then certainly there would be reason to communicate the no apples state. It is ignored in communication when it does not provide useful information, but it is not forgotten. The 0th index is implicitly there.
- anigbrowl 4y ago
- yongjik 4y agoThat's why I prefer the Superior(TM) Korean age counting. You are one year old when you're born (it's your first year!). You are two year old on the next New Year's day. (Congratulations, it's your second your now!) So, if you're born on December 31st, you're two years old the next day. (I see no problem, but apparently some people are hung up on such minor details. I can't fathom why.)
- galangalalgol 4y agoDoesn't Korea use the same new year as China? Usually second new moon after winter solstice.
- smegsicle 4y agohung up on minor details!
- gumby 4y agoThis system is used for racehorses as well.
- tromp 4y ago> You are one year old when you're born (it's your first year!) That makes no sense to me. It's also your first century. Does that make you one century old? Of course not! The moment you're born, you're not even one hour old, let alone one day.
- BuckRogers 4y agoThey must like rounding up. I guess it depends how they refer to it in their language. If it's "he's in his 1st year", that's a big difference from, "he's 1 year old". I'm wondering if the parent comment simply doesn't know Korean or only knows it somewhat to misconstrue the culture behind this. It could be though that Korea simply never encountered the Mayan or Arabic civilizations as most did encounter one of those two in history, who are famously known to have independently discovered the concept of zero. Birth of an array can only logically be defined as index zero, the same as a child. The concept of zero was not universal globally and Korea is pretty isolated.
- drewzero1 4y agoOddly(?) though, most parents of young children don't refer to a baby as being "zero years old." Rather, we break them down into smaller units: two days old, six weeks old, four months old.
- throwaway821909 4y agoIt helps that change happens particularly fast at that age, so the difference between newborn and 6 months is worth mentioning. Later on the units go up again and we just say "I'm in my 30s" :P On the other hand a computer/car/house can also be 10 years old but not 0.
- drewzero1 4y agoTrue, a few weeks can mean a few milestones at that age. It's still wild to me how quickly babies/kids develop. Every week brings new abilities, experiences, and emotions that weren't there before.
- wruza 4y agoOn the other hand a computer/car/house can also be 10 years old but not 0 Really? When I buy a new PC, to me it will get 1 year old only after a year. Before that it is just NEW. Is that what you meant?
- pvinis 4y agoExactly. What we call "new" is the 0th year. It's the same when you start counting seconds. You say "ok counting starts now", then wait a second and say "one", then wait and say "two". Before you say "one", you don't say zero, but it's implied by you waiting a second after you or someone says "go". That's still 0-indexed.
- samatman 4y agoDuration only ever departs from 0, it can never arrive there. That's why zero-based indexing is good!
- lupire 4y agoThe first floor in a USA building is not where a European would expect.
- ellen364 4y agoDemographers sometimes describe age as “the number of completed years”, which always struck me as a wonderfully simple explanation.
- croes 4y agoIf you think of the index as an offset you would start with 0. BTW on which level is the 1st floor?
- enobrev 4y agoYou've got ...P3, P2, P1, G, M, 1, 2, 3...
- 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.
- 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?
- 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.
- 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.
- amalcon 4y ago"Offset-based" is bringing in pointers; that's the thing it's an offset "from". "The beginning of the array" is just a pointer. I suppose saying that does have an advantage over explicitly talking about pointers, in that the word "pointer" is a piece of jargon that has a lot of baggage. That's just avoiding jargon, though, not really using a different model.
- samatman 4y agoNo, offset means "measuring from origin", pointers use that language they don't provide it. The advantages in measuring from origin can accrue to the person choosing to do it, because there are other reasons to do so which aren't satisfying the CPU.
- amalcon 4y agoNo, offset means "measuring from a defined location". In a computer, the choice of location is more or less arbitrary[0]. If you pick the first element, you get zero indexing. If you pick a space before the first element, you get one indexing. Either one is a pointer, since a pointer is just computer jargon for "a defined location". Calling that defined location "origin" doesn't suddenly make it not a pointer. [0]- NUMA and cache effects aside, as they don't matter for this purpose
- 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".
- 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.
- jcelerier 4y agoAt which number starts the first centimeter on a ruler ?
- 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.
- 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.