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!
Numbering Should Start at Zero
51–58 of 58 posts
Re: Numbering Should Start at Zero
#52Dijkstra 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.
Re: Numbering Should Start at Zero
#53So 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…
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
#54If 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.
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
#55So 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.
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
#56Earlier 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.
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
#57Dijkstra 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…
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
#58Earlier 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.