Skip to main content
3 events
when toggle format what by license comment
Jul 11, 2015 at 14:43 comment added supercat @phyrfox: The abstraction I prefer for zero-based indexing is to say that indexes identify positions between objects; the first object lies between indices 0 and 1, the second between 1 and 2, etc. Given x<=y<=z, ranges [x,y] and [y,z] will be consecutive but not overlap, and either or both may be empty with no special corner cases required. When adopting the "indices sit between items" model with zero-based indexing, a list of six items spans the range from 0 to 6; with one-based indexing it would sit from 1 to 7. Note that this abstraction fits well with "one-beyond" pointers.
Jul 10, 2015 at 22:01 comment added phyrfox Actually the zero-based and one-based indexes have to do with how the array is constructed in memory. Zero-based indexes use external memory (external to the array) to determine size, while one-based indexes use internal memory (index 0) to remember the size of the array (usually, anyways). It's not popular for "the size of the object" but usually has to do with how the memory is internally allocated for arrays. Regardless, I wouldn't recommend recklessly leaking bytes here and there "just because." But dictionaries are usually a better idea anyways.
Jul 10, 2015 at 7:40 history answered david CC BY-SA 3.0