"Newbie" questions - "unique" sorting ?

Anton Vredegoor anton at vredegoor.doge.nl
Sat Jun 28 04:44:17 EDT 2003


"Cousin Stanley" <CousinStanley at hotmail.com> wrote:

>    Edited version of screensaver.py ....
>
>        http://fastq.com/~sckitching/Python/scr_av.py
>
>I'm sure you will hate it,
>but it's much easier for me to read ....

On the contrary, I am very glad someone reads my code and make changes
to it, for better or worse! The more "eyeball" inspection code gets,
the more chances it has into evolving into something better, even if
sometimes newer versions of the code are worse than earlier versions.
It works like a genetic algorithm improving ones code snippets :-)

The other thing is that while using Python it seems to be common to
read ones previous code and discover that code from only a few months
ago would be done very differently now. For example my screensaver
module imports a "sequencer.py" file that could now be rewritten in
probably a fourth of the number of lines, because someone on c.l.py
here made a comment on a newer version of it that was already half the
number of lines of "sequencer.py". Also the "Transformer" class in the
screensaver needlessly recomputes a lot of things at every call that
could be done during initialization, later versions of this class are
doing this better.

My personal observation is that *everything* I write in Python is a
candidate for improvement in only a few months time because of my
changing perspectives on the matter. For another perspective on the
"lulu" code for example, try this :

    trans = [string.lower(chr(i)) for i in range(256)]
    for i in range(256):
        if not trans[i] in string.letters: trans[i] = ' '
    trans = ''.join(trans)

I think this is both a line or so shorter than the original code and
is probably also a bit clearer. Because IMO everything written in
Python is improved sooner or later -according to how many people look
at it- I expect *this* code fragment to be updated once again soon. 

This peculiar aspect of Python (and probably other high level
languages) is probably caused by the fact that Python code comes
closer to ones thoughts than other code, and -at least for me-
thoughts are the most volatile elements in the world.

So better get used to it (if your experience is anything like mine of
course) and don't let yourself be distracted by the code-reusers,
unit-testers, and static typers that are still trying to get a grip on
this elusive aspect of Python coding.

Anton









More information about the Python-list mailing list