A modest indentation proposal

Skip Montanaro skip at pobox.com
Thu Nov 29 18:35:20 EST 2001


    Erann> Personally I've found [indentation-based block structure] to be
    Erann> less of a problem than I thought it would be, but annoying
    Erann> nonetheless.  It also IMO makes the language unsuitable for
    Erann> mission-critical applications.  It's just too easy to screw up
    Erann> indentation (particularly when cutting and pasting large blocks
    Erann> of code) without realizing it.

As has been demonstrated many a time, you're more likely to screw up a C
block by omitting braces:

    if (cond)
        x = 1;
        y = 1;

than you will screw up a Python block.  In fact, it's such an insidious
problem in C code that many groups mandate that all blocks use { & }, even
for one-statement blocks.  In Python, if it looks right, it is right.  In
practice, this has not proven to be a problem.  I've been using Python as my
primary programming language essentially full-time since 1994 with never a
problem in this regard.  I don't know.  Maybe I'm just weird.  I prefer to
think not though.

    Erann> I propose to use a semicolon at the end of a line to denote the
    Erann> end of a block, e.g.:

    Erann> for i in l:        # Colon signals beginning of block
    Erann>   foo()
    Erann>   baz(); boff()    # Semicolon separating statements works as usual
    Erann>   bar();           # Semicolon at end of line signals end of block
    Erann> biff()

In my book trailing single-character punctuation should be avoided wherever
possible.  (That goes for single-element tuple literals as well.)

I suggest you just use

    # end if
    # end while
    # end for

as your block closers and apply Tools/scripts/pindent.py

    Erann> This convention is 100% backwards-compatible with current
    Erann> practice, that is, code written using this convention runs with
    Erann> no problems in Python as it currently stands.

Not it's not.  Semicolons can legitimately be used to end a statement now.

was-that-troll-spit-i-just-stepped-in?-ly, y'rs,

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list