[Tutor] Code Readability (was: Recursion and List Comprehensions)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Oct 30 00:45:20 CEST 2005


> > I agree.  When writing for keeps (i.e. production code) I prefer
> > clarity and ease of maintenance over 'elegance' or 'trickiness'.
> > This exercise is intended, in part, to sharpen my understanding of
> > Python idioms.  If I can write highly idiomatic code that works,
> > chances are better that I will be able to decipher it when I come
> > across it elsewhere.

> Since when is elegance a dirty word?

It's not.  But there are tradeoffs.  As a concrete example, we can take a
look at Bram Cohen's fairly recent request for a pure-Python suffix tree
implmementation:

    http://www.livejournal.com/users/bramcohen/22069.html

He's specifically requesting for an implementation for a data structure
algorithm that is easy to maintain, and he's willing to sacrifice the
elegant optimal solution!  But that's because he wants to make sure he can
understand the code later on.

I'm not sure I agree with Bram --- the "Ukkonen" algorithm for building
suffix trees isn't bad, and I can probably cook it up if I'm careful ---
but I can see why he values a simple implementation.



More information about the Tutor mailing list