Re: 0-based Indexing
- Posted by dm31 at uow.edu.au Jul 17, 2003
- 493 views
>From: "C. K. Lester" <cklester at yahoo.com> >Derek splained (snippage occurred): > >> > I don't get it. Why do some languages use 0-based indexing? It's got to >be >> > the dumbest thing in programming language history. Or maybe not. >> > >> The index is actually an offset from an address. > >Okay, I get that... and that's reasonable for the behind-the- scenes data >manipulation, but why not hide that detail and use 1-based indexing? Is it >that much of a performance issue? Like Greg said, 1-based indexing is more >intuitive, easier to read and understand... Well, for me personally (maybe because I'm use to programming in C/C++/ASM) 0-based is easier and more understandable. Also, for example. say I want to use 1 byte of storage as my index var. If I start at 0, I get from 0-255 different elements, whereas if I used 1-base then I could only get 1- 255. Having 0-based makes some algo's cleaner to write, and more effiecent. (in above example use a 256 length array, I only need 1 byte for 0-based, and 2 bytes for 1-based. Not much of a difference, but I'm a large program with many of those it would) Cheers, Dan