[Edu-sig] Re: In defense of 0, was Re: None potato, one potato, two potato, more..

Christopher A. Craig com-nospam at ccraig.org
Mon Jan 5 10:56:13 EST 2004


Arthur <ajsiegel at optonline.net> writes:

> Kirby writes -
> >C is zero-based, like Python, no?
> 
> K-12 is also zero based, effectively.
> 

Okay, I'm a bit off topic here, but that's a historical artifact.  If
pre-k were added in it would be effectively -1 based, which would
still be irrelevant.  

Coming slightly back to topic the important to thing remember about
teaching 0 based indexing (and I'm admittedly a programmer, and only
teach to my Boy Scouts) is that array indexing measures the _distance_
from the beginning and not the number of the item.  So we can imagine
we have a (metric) ruler and a set of items, each one cm long and
denoted here by letters:

0 a 1 b 2 c 3 d 4 e 5

Then everything makes perfect sense (except for why they chose such a
screwy indexing scheme which won't make sense until much later):

[0] would indicate the item sitting 0cm from the beginning (a)

[2] would indicate the item sitting 2cm from the beginning (c)

[0:3] would indicate the items from the beginning (0) to 3 cm from the
beginning (i.e. a,b,c)

[-1] indicates the item sitting 1cm from the end (e)

-- 
Christopher A. Craig <com-nospam at ccraig.org>
"By rights we shouldn't be here." -- Sam in Peter Jackson's 
"The Two Towers" while standing in Osgiliath, where he shouldn't be.




More information about the Edu-sig mailing list