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

Steven D. Majewski sdm7g at Virginia.EDU
Thu Jun 21 23:17:18 EDT 2001


On Thu, 21 Jun 2001, Chuck Esterbrook wrote:

> >Zero is natural whenever you are thinking in terms of offsets:
> >   every ruler starts with an implied 0 inches (or cm. or other).
> 
> Rulers don't have much to do with lists. The first measures; the second 
> contains.

True. But the initial discussion was about a function that finds the
offset into a string of a substring.  And when you have to add or
subtract those offsets, zero based offsets are better. We're talking
about what is essentially "pointer arithmetic" even though there are
no C pointers involved. ( That's the real reason C is zero based --
where ever they got the idea from! ) 

Whether strings should even be considered sequences is another one of
those engineering tradeoffs. I've had and seen lots of code that 
wants to crawl thru possibly nested sequences and do something to
the things at the end-leaves. Sometimes strings are supposed to be
the exception -- sometimes they aren't. Makes it difficult to write
generic code.  Lisp has both atomic-symbols and string-sequences,
and you can convert from one to the other, so it's possible to 
get the behavior you want from a generic function if you're willing
to be specific with your input. ( Also, symbols are interned strings,
so equality testing is just pointer comparison -- and all of the 
things you do to symbols are usually 'atomic' in the same sense --
you don't need to see their parts. ) 


I don't disagree with most of your other points -- except that I 
know that *I* learned zero based sequences in High School math -- 
 N-sub-zero, N-sub-one, ... and I think I've seen it in my kids
homework. 

-- Steve Majewski







More information about the Python-list mailing list