[Python-Dev] Re: Dafanging the find() gotcha
Guido van Rossum
Tue, 06 Aug 2002 11:36:13 -0400
> Michael> I think this is an extremely unconvincing example. You have
> Michael> pushed the API up to the user of a program and supposed that
> Michael> they expect the behavior which you are trying to defend. In
> Michael> practice, what users expect in cases where a field is left
> Michael> blank is for that field to be IGNORED, not for it to be
> Michael> processed, but its contents treated as containing an empty
> Michael> string.
> I understand. My point is that in this particular example, what the
> user perceives as ignoring the request is obtained by the
> implementation technique of treating it as an empty string. The user
> doesn't have to know about this implementation technique, of course.
I think it's a poor implementation technique. :-) Opening the file to
search for an empty string is very inefficient.
My own potential example was some kind of graph traversal algorithm,
representing paths by sequences of letters (the letters labeling
edges), and involving paths that are subpaths of other paths.
Certainly the empty path should be considered a valid subpath of other
BTW, a more fool-proof (though unfortunately slower) way of testing
for substring containment in existing Python would be s2.count(s1) --
this returns the number of occurrences. And of course,
'abc'.count('') returns 4.
--Guido van Rossum (home page: http://www.python.org/~guido/)