statements and blocks

Tim Peters tim_one at email.msn.com
Sat Jan 29 04:28:37 EST 2000


[rdudfield at my-deja.com]
> Speaking of blocks, is there a way to show where the block ends?

How about adding a comment <0.5 wink>?

> I have been caught a few times doing this:
> class b():
>   def asdf():
>     print 'a'
>     if bla:
>       print 'a'
>       print 'a'
>       ... more than a page of stuff.
>
>    # method is supposed to be in the classes scope.
>     def qwer():
>       print 'a'
>       print 'a'
>       print 'a'
>
> Basically because the function asdf is more than a page long.
>
> I find indentation is better in most cases except this.  This isn't too
> much trouble, as I usually find the problem pretty quickly.  However
> occasionally I waste a bit too much time on it than I'd like to :)

Quite a few years ago I dug up this quote from Donald Knuth, which has since
been widely misquoted in the Python world:

    We will perhaps eventually be writing only small modules which are
    identified by name as they are used to build larger ones, so that
    devices like indentation, rather than delimiters, might become
    feasible for expressing local structure in the source language.

    Donald E. Knuth, "Structured Programming with goto Statements",
    Computing Surveys, Vol 6 No 4, Dec. 1974

A key word there is "small":  indentation sucks for functions that slobber
over pages.  The solution is obvious:  don't write functions that slobber
over pages!  You can do *so much* in so few lines of Python that there's
simply no good excuse for violating common sense here.  It's one of the ways
in which Python (not so) subtly encourages good practice.

easy-readability-is-an-author's-greatest-achievement-ly y'rs  - tim






More information about the Python-list mailing list