[Python-ideas] An iterable version of find/index for strings?
Tom Schumm
phong at phong.org
Mon Apr 8 20:59:15 CEST 2013
On Mon, April 08, 2013 11:04:40 AM Andrew Barnert wrote:
> But that's not the important part. The benefit of startswith is that it
> takes less effort to read and understand the code. Reading a regex, or
> s[:5]=='start' for that matter, isn't _hard_, but it still takes a bit of
I was a big fan of regular expressions, going way back; I was a huge Perl
fanatic. But over the years I've used them less and less. As Andrew says, if
you have a simple string method that does the job, why endure the cognitive
overhead of a regular expression? Even if you are using a great regex library
that optimized out the computational overhead for simple cases, you still have
to write a (potentially cryptic) regex, escape special characters, etc.
It's a win if you can make code self-documenting by using a descriptive method
like "startswith", "endswith", "if needle in haystack", "find", "strip", etc.
All those have trivial regex solutions, but it's better to just say what you
mean.
--
Tom Schumm
http://www.fwiffo.com/
More information about the Python-ideas
mailing list