Another Wart! string.find() [ was: namespace issue? ]

Steven D. Majewski sdm7g at Virginia.EDU
Thu Jun 21 22:19:28 EDT 2001


On 21 Jun 2001, Chuck Esterbrook wrote:

> "Steven D. Majewski" <sdm7g at Virginia.EDU> wrote in message news:<mailman.993163773.29922.python-list at python.org>...
> [snip]
> >
> >   I'ld love to see it fixed, however, I suspect that in this case, 
> >   many lines of installed code trumps Computer Programming for Everybody! 
> > 
> 
> So is it a flaw, relative to CP4E, that sequences start at index 0
> instead of 1? An 'everybody' kind of person would think of the "first"
> element as e[1]. Only someone familiar with pointer arithmetic from C
> or assembly would think that "first" is 0.

No -- that's not a "flaw" , it's an "engineering tradeoff" -- i.e. 
you can't please everyone all the time! 

Zero is natural whenever you are thinking in terms of offsets:
  every ruler starts with an implied 0 inches (or cm. or other).

Zero based indexing makes slice indexing much easier to figure -- 
  one-based indexing would make that more confusing to everyone. 

Lots of other technical fields besides programming use zero based
 indexing -- where do you think C got it ? Probably from mathematics
 or engineering. Most high-school grads should be familiar with 
 the notation. 

Yeah -- there are arguments for 1 over 0, but whatever you choose 
is going to be 'wrong' for somebody, some of the time. 

And not surprising C programmers does have *some* value. 

( But I can't really think of a good reason for string.find to return 
  -1 *except* that it wouldn't surprise a C programmer. ) 


-- Steve Majewski






More information about the Python-list mailing list