Python is readable

Steve Howell showell30 at yahoo.com
Tue Mar 20 21:28:25 EDT 2012


On Mar 20, 5:22 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Tue, 20 Mar 2012 15:28:25 -0400, Nathan Rice wrote:
>
> > What if you are composing
> > three or four functions, each of which is conditional on the data?  If
> > you extract things from a statement and assign them somewhat arbitrary
> > names, you've just traded horizontal bloat for vertical bloat (with a
> > net increase in volume), while forcing a reader to scan back and forth
> > to different statements to understand what is happening.
>
> First off, vertical bloat is easier to cope with than horizontal bloat,
> at least for people used to reading left-to-right rather than vertically.
> There are few anti-patterns worse that horizontal scrolling, especially
> for text.
>

I agree with Steven that horizontal bloat hurts readability more than
vertical bloat.  Of course, it's a subjective thing, and I get the
fact that the remedy to horizontal bloat often means more volume of
code overalls (i.e. introducing locals).

My main problem with horizontal bloat is that you often have to read
inside-outside or right to left:

    verb3(verb2(verb1(noun)))
    verb2(verb1(noun, adverb1), adverb2)

The vertical versions tend to be more verbose, but entirely
sequential:

    noun1 = verb1(noun)
    noun2 = verb2(noun1)
    verb3(noun2)

and

    noun1 = verb1(noun, adverb1)
    verb2(noun1, adverb2)


There is a bit of an inflection point when the number of lines in the
"local" code exceeds the vertical real estate of your monitor.  I feel
like vertical real estate is still mostly constrained by the way we
build our monitors and our editors, and it's not so much a "human
brain" limitation.  With horizontally stretched code, I always feel
like my brain is the bottleneck.

The one place where I don't mind the horizontal approach is when code
is truly laid out in the order of execution:

  noun.verb1(adverb1).verb2(adverb2).verb3(adverb3).verb4(adverb4)

Even then, I'd prefer it to read vertically.  Also, while the above
idiom puts the verbs in the right order, it is still backward to me to
say "noun.verb."  You don't noun a verb.  You verb a noun.






More information about the Python-list mailing list