Slight irritation with try/finally indentation

François Pinard pinard at iro.umontreal.ca
Sat May 4 11:23:01 EDT 2002


[Stephen J. Turnbull]

> >>>>> "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()

Clever, and nice.  Thanks for this idea, I'll ponder it.

> Alternatively, to be truly perverse: [...]

It seems you are teaching us that there is beauty in some perversions! :-)
It might become a bit dangerous to over-push on that thesis, however...

                                        Keep happy, all!

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list