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

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 :-).




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

Search: