Live data from Hacker News

Numbering Should Start at Zero

cs.utexas.edu

51–58 of 58 posts

Re: Numbering Should Start at Zero

#51

Earlier quoted context omitted.

In addition to code, I think 0-indexing is also a nice convention for floor numbering. That way the Nth floor is N floors up from the ground level. This is already how basement levels work.

I agree. Touche!

This is not a 6-hour slow risposte; it's my 6 hour anti procrastinate filter I swear. Anyway, just like all animals of habit, I immediately I agreed with floor zero because I come from a place where the lowest floor is not floor 1 (unlike the US). However, I can see somebody saying floor is the height of the ceiling, so floor 1 = 10 feet; floor 0 (underground) 0 feet. One thing we can all agree is that the calendar, without a zero, it's pretty bad.

Re: Numbering Should Start at Zero

#52
post #28

Dijkstra have a certain way of writing as if his argument follows by logical necessity. But when you dig into the chain of reasoning, it hinges on the assertion that starting with 0 is "nicer". Which is of course a valid opinion, but starting with 1 also have nice properties, for example that the numbering of elements corresponds to the ordinal numbers. Having the first element be element 1 is pretty nice IMHO. He en…

Yes, I also had found that paper to be surprisingly and disappointedly hand wavey. "Don't meet your heroes" type of thing. Math does not care about pointer arithmetic and i in summation and induction starts at 1. Same in Julia. It's an higher level accommodation to machine code primitives, which are indeed less gate expensive if indexes start at zero.

I’m not sure about this. I’ve seen more index from 0 for induction and summation in Analysis.

Re: Numbering Should Start at Zero

#53

So the first item in my array of 13 items is at position '0'. The 3rd item is at position '2'. And if I want to count the items in my array I start at '0' and keep going until I get to '12'. Even though there are 13 items in my array? I see. zero-indexing is good for system-level stuff, for dealing with actual memory and so on, but I'm still not convinced it's the right way. It's certainly not the one true way, 1-bas…

By now we've been doing

    for (int i=0; i
for decades. No point vastly messing up consistency for minimal gain. BTW notice how in both cases we count to n elements despite using 0..n-1 indexing. You don't, in fact - need to put 12 anywhere if you mean 13 elements.

Re: Numbering Should Start at Zero

#54

If I have some apples on a table and pick single apple up, I don’t have zero apples in my hand. I think that’s why numbering doesn’t start at zero.

before picking up apple

    table = {apple0, apple1, apple2, apple3}; //length == 4
    hand = {}; //length == 0
after

    table = {apple0, apple1, apple2}; length == 3
    hand = {apple3}; //length == 1
You count apples in hand by looking at how many items there are, not by what indexes they have.

Re: Numbering Should Start at Zero

#55
post #53

So the first item in my array of 13 items is at position '0'. The 3rd item is at position '2'. And if I want to count the items in my array I start at '0' and keep going until I get to '12'. Even though there are 13 items in my array? I see. zero-indexing is good for system-level stuff, for dealing with actual memory and so on, but I'm still not convinced it's the right way. It's certainly not the one true way, 1-bas…

By now we've been doing for (int i=0; i for decades. No point vastly messing up consistency for minimal gain. BTW notice how in both cases we count to n elements despite using 0..n-1 indexing. You don't, in fact - need to put 12 anywhere if you mean 13 elements.

But

  whatever[1]
gives the second item, and the last item, of 13, is

  whatever[12]
fortran has been 1-based since well before these examples.

The point is there is no one true way, it's a trade-off.

Re: Numbering Should Start at Zero

#56
post #38

Earlier quoted context omitted.

zeroth is the ordinal associated with the cardinal zero. For example christmas is the zeroth day after christmas. A common advice with regards to user inputs is that if you do not do ordering or arithmetic on a piece of data (eg a phone numbers) then it should be a string even if it is numeric. Similarly n-indexed conventions should be considered in terms of practical pros and cons. Linguistic similarity is not a con…

'associated'? Sounds nice, but not very convincing, except perhaps the zeroth item of an ordered set should be just that, 0. I agree indexing is a trade-off, sometimes 0 is best, sometimes 1 makes more sense. But it's not linguistic 'similarity'. You have to name things. If your names are off-by-one (the element named 'first' is actually the second) you're just sowing confusion.

sometime ordinals are more natural sometimes cardinals are more natural.

In the case of vectors (especially of C-style arrays) I would say that A[0] is the first element in the array. I agree that things should have names, but names serve us, not us them.

Re: Numbering Should Start at Zero

#57
post #28

Dijkstra have a certain way of writing as if his argument follows by logical necessity. But when you dig into the chain of reasoning, it hinges on the assertion that starting with 0 is "nicer". Which is of course a valid opinion, but starting with 1 also have nice properties, for example that the numbering of elements corresponds to the ordinal numbers. Having the first element be element 1 is pretty nice IMHO. He en…

"And anyway, isn't the "corporate religion" these days to start with 0, since this as what the big mainstream languages does? "

Exactly this. Our firm had been forced to change numbering of real-life items from 1-based to 0-based, because some cargo-cultist somewhere was amazed by the offsets and addresses and wanted to force this numbering scheme everywhere. Now there is a code inside that converts 1-based items to 0-based for legacy stuff, and we are still finding bugs caused by that. Every day to day operations are artificially harder because understanding what is actually unit number 1 or port number 2 is hard now, just like counting total number of anything and remembering to add 1 afterwards. But now we get to have a hype 0-based everything system, which nobody asked for. In some cases this can lead to such awesome combos like physical ports numbered 1-based, then 3rd party switch with 0-based, then Linux interface on top 1-based, then our config on top 0-based. Amazing and convenient, isn't it?:)

Re: Numbering Should Start at Zero

#58

Earlier quoted context omitted.

Yes, I also had found that paper to be surprisingly and disappointedly hand wavey. "Don't meet your heroes" type of thing. Math does not care about pointer arithmetic and i in summation and induction starts at 1. Same in Julia. It's an higher level accommodation to machine code primitives, which are indeed less gate expensive if indexes start at zero.

In addition to code, I think 0-indexing is also a nice convention for floor numbering. That way the Nth floor is N floors up from the ground level. This is already how basement levels work.

0-based floor numbering is infuriating. Telling someone that you live on the third floor which is actually numbered 2 is honestly dumb. I had to emigrate from the 1-based floor country a year ago and first floor numbered 0 is still throwing me off sometimes. And every single time I want to raise attention to a window somewhere.
Post reply on HN