Slight irritation with try/finally indentation

Ype Kingma ykingma at accessforall.nl
Wed Apr 24 15:12:08 EDT 2002


François Pinard wrote:
> 
> Hello, people.
> 
> There is something which I find slightly irritating with the try/finally
> construct, and wonder if someone would not have a good advice to offer.
> I guess it is very usual that one has, within a suite, something like:
> 
>     [...]
>     setup()
>     process()
>     cleanup()
>     [...]
> 
> with `cleanup' undoing the effect of `setup', more or less, really seeing
> `setup()' and `cleanup()' as a kind of big parentheses around `process()'.
> In a context where `process()' may raise exceptions, `cleanup()' might be
> mandatory once `setup()' has completed, so one rewrites the above as:
> 
>     [...]
>     setup()
>     try:
>         process()
>     finally:
>         cleanup()
>     [...]
> 
> What I find irritating is that `cleanup()' is not aligned anymore with
> `setup()', as it was originally, so we loose on the legibility of the
> parenthetical idiom we wanted to stress.  Surely, I may _not_ write:
 
It's a bit irritating indeed. I occasionaly use the non indented form:

    setup()
    try: process()
    finally: cleanup()

but it only works for single lines and gives a bit more work when
lines have to be added, so this form tends to disappear over time...

Have fun,
Ype


-- 
email at xs4all.nl



More information about the Python-list mailing list