[Edu-sig] Using try / except: any stipulations against routine use?

Laura Creighton lac at openend.se
Thu Dec 15 00:08:48 CET 2011


In a message of Wed, 14 Dec 2011 14:36:43 PST, kirby urner writes:
>> Isn't this at least as readable, and conceptually simpler?
>>
>> if ext in res_dict:
>>    res_dict[ext] += 1
>> else:
>>    res_dict[ext] = 1
>
>I get that a lot too and often propose my one-liner.  This is not a
>matter of flagging a mistake, just showing another way.
>
>It's a chance to learn dict methods better and hey, they're paying to
>have a pro coach.
>
>Kirby

This looks suspiciously like 'I am a superior being because I know more
obscure methods that you do, and obscure knowledge defines the professional'.
Bleah.

By my standards, this is _unprofessional_.  Whenever you have the urge
to write code to show off how smart or how knowledgable you are, kick
yourself.  Professional code is meant to be read.  If you make the
general reader go off to the manuals to find out why something is
done, then you ought to have a darn good reason for doing it that way
than the way that everybody can read and understand.

Personally, I think that Python would be a much better language if it
had fewer of these sorts of methods, thus forcing people to use syntax
like Bert Freudenberg posted above, because the more obscure ways
aren't available.  Now we have to rely on personal self-discipline to
not use them, even when we know them, and a deep, unshakeable faith
that code is meant, first and foremost to be _read_, and read by
_everybody, not just the other 'experts' -- an expert being one who is
defined here as 'one who is well-steeped in Python obscurity as you are'.

If we loose the ability to read Python, because all the new graduates
are writing code that is hard to read as a matter of principle --
because they think it is superior, or a matter of ego -- because it
shows off their knowledge and maybe their cleverness, then I might as
well be reading any other language.  We'll have lost the primary thing
that I think makes Python valuable, via the 'boil-the-frog' principle.
http://en.wikipedia.org/wiki/Boiling_frog

I think as educators it is our job to make sure this does not happen by
teaching the appropriate self-discipline.  I'd like to send your top
students back their code with the comment, 'Great that it works.  Now can you
make it more readable?' I'd be looking for code like the above to replace
code like yours.

Laura


More information about the Edu-sig mailing list