Slight irritation with try/finally indentation

Stephen J. Turnbull stephen at xemacs.org
Thu Apr 25 22:55:44 EDT 2002


>>>>> "François" == François Pinard <pinard at iro.umontreal.ca> writes:

    François> What I find irritating is that `cleanup()' is not
    François> aligned anymore with `setup()', as it was originally, so
    François> we loose on the legibility of the parenthetical idiom we
    François> wanted to stress.  Surely, I may _not_ write:

    [...]
    try:
        setup()
        process()
    finally:
        cleanup()
    [...]

    François> despite it would look nicer, because if `setup()' fails,
    François> `cleanup()' gets called when it should not have been.

Of course you may not write that.  You must write

    try:
        setup()
        process()
    except SetupError:
        pass
    else:
        cleanup()

I think that you're trying to bind setup() more closely to process()
and cleanup() than your assumptions about failure modes allow.

Alternatively, to be truly perverse:

    try:
        setup()
        process()
    except ProcessSuccess:
        cleanup()

-- 
Institute of Policy and Planning Sciences     http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
 My nostalgia for Icon makes me forget about any of the bad things.  I don't
have much nostalgia for Perl, so its faults I remember.  Scott Gilbert c.l.py



More information about the Python-list mailing list