Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Read their explanation though:

"For example, the coefficients of a polynomial a0 + a1 x + a2 x2 + . . . + an xn clearly cry out for the zero-offset a[0..n], while a vector of N data points x i , i = 1 . . . N calls for a unit-offset x[1..N]"

The polynomial cries out for zero for a real mathematical reason. Zero really is more natural there. The vector of N data points "calls" for a unit-offset because, um, convention?



Yes, right! Again, "context is the key to knowing which one is better."

We are violently agreeing, we don't really need to twist words or attempt to disprove what might just be a poorly worded statement, right? We are all educated engineers here, and we can afford each other the benefit of the doubt, no? We both get it.

The important part of the point is that all the other arguments here about which choice is inherently more "natural" is somewhat bogus. Neither is inherently more natural, what is more natural depends on what you're trying to do.

In some cases, there isn't an obvious choice, that's where convention plays the biggest role, but having a default choice made for you doesn't make the convention better or more natural, it just makes it an arbitrary choice that everyone is used to.


I agree that we're having an educated and civil discussion.

And I agree with the sentiment of using the right tool for the job, in principle.

However, I disagree that we're in full agreement :). I actually do think that there is a choice here that is inherently more natural for the sufficient majority of general-purpose tasks. The main arguments I'm aware of against it are arguments purely from human convention, which I find are not always as "natural" as one might hope.


So, is the implication that you feel zero-based is the inherently more natural? Or one-based? Truly just curious, and I'm not about to argue over it. :)

Personally, even though I'm not used to it, I could probably be convinced that one-based might be the right "general purpose" answer for looping through an array when not doing any math on the index. Often when doing any math on the index, zero-based is much better. I do a lot of index based math, and yet if I'm being honest, I'd say the vast majority of my loops and the loops in code around me probably don't play index tricks and could use either indexing scheme.

Funny enough, I do a lot of graphics and image processing, and the OP referenced a joke about splitting the difference and using 0.5 -- I used 0.5 indexed arrays all the time! Logically, not syntactically -- I mean I take pixel samples starting from the center of a pixel, which is indexed by (ix+0.5,iy+0.5). If there were such a thing as a 0.5 index, I would use it. :P


Oh, I thought I was clearer than I was. I feel zero-based is more natural.

However, I do agree with you that in the vast majority of loops there aren't any interesting index tricks. For this reason, I actually think language constructs like "foreach" and iterators and so on are better than counting from either 0 or 1 in most cases. In high-level languages, use high-level looping constructs, and let the compiler figure out the indices for you :-).


> The vector of N data points "calls" for a unit-offset because, um, convention?

I think ordinality reflecting cardinality is, while a convention, more than a purely arbitrary convention. And even if it is a purely arbitrary convention, its one that is so pervasive in dealing with collections outside of computing that it is a cognitive burden not to match it in computing (its a cognitive burden that you get used to dealing with pretty quickly when you've been immersed in languages that don't support it naturally, but its a cognitive burden nonetheless.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: