Need better string methods

Stephen Horne steve at ninereeds.fsnet.co.uk
Sun Mar 7 14:11:57 EST 2004


On Sun, 7 Mar 2004 08:29:21 -0600, Skip Montanaro <skip at pobox.com>
wrote:

>My arguments from the "Zen of Python" would be:
>
>    Beautiful is better than ugly.
>    Simple is better than complex.
>    Sparse is better than dense.
>    Readability counts.

Sparse can certainly be better than dense, but it is not an absolute.
With any style rule there is a need to balance issues and to use
common sense. If code can be made denser while still being readable
then more functionality can be viewed on screen at once - a major
benefit in readability and understanding as the more you can see, the
less you have to remember.

The Ruby code was IMO easier to understand Davids 'best' Python
(except for the regular expression). The left-to-right sequencing is
really no different than top-to-bottom sequencing in readability
terms. And adding comments is pointless when those comments just
duplicate what a standard method name already tells you - worse than
pointless, in fact, as it obscures the code that you're trying to
read. Good names are better than compensatory comments, and anyone
claiming to be a programmer should know the everyday names that are
used in his chosen language.

I know that isn't what your comments did, but my point is that the
Ruby example really doesn't need them. The nearest equivalent Python
code requires a temporary variable and either semicolons or splitting
over a few lines - the latter is probably better, though I adopted the
former in my earlier post. Simply breaking the code up, though,
provides no real readability benefits.

Put it this
way. How
much am I
improving
the
readability
of this
paragraph
by making
it stupidly
narrow like
this?

Splitting a perfectly clear line of code over several lines is exactly
the same thing and, as I said, the only readability issue that I could
see in the Ruby code was the regular expression.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk



More information about the Python-list mailing list