approach to writing functions

Anton Vredegoor anton at
Tue Feb 10 13:56:02 CET 2004

"Terry Reedy" <tjreedy at> wrote:

>> Just asking for a bit of guidance. If my program works, should it be
>> re-written to use functions or classes?
>Working correctly is most important.  Next is running fast enough.  Then
>you can consider whether you or another person can read, edit, or reuse six
>months from now.  As for rewriting, would *you* gain some personal benefit
>from doing so?

I disagree with the order in which you list these things, but that
might be caused by whether one sees Python as a language to express
ideas or as a tool to accomplish a more specific task. For example I
am not a native English speaker, but I guess nobody would think it
more important to avoid all spelling errors than to get the idea

Posting scripts and ideas that are in this stadium is a bit dangerous
and one may end up with some egg (or pie!) in ones face, but since
software development is promoted most by removing errors in the
*early* stages it's a good strategy I think. Of course this shouldn't
result in long posts here with completely unqualified code. 

However, asking specific questions about smaller functions is better
than posting 100+ lines of code and requesting that someone explains
why the script doesn't do what it is meant to do while it is still
unclear what a poster really wants the script to do.

While developing code I'm imagining a herd of virtual Python gurus
looking over my shoulder assisting me and requiring my code to be
readable ...

What I am trying to say is that if one develops code *as if* posting
it here, errors are detected sooner. And later errors are more costly
than early errors.

Anyway, I want more people to post code, even if it is not perfect!

Only after a lot of "eyeballing" and splitting the code up into
functions one should go to the next phase of testing the script for
possible errors and behavior in worst case scenarios. Of course Python
also accommodates for a grand unified style of programming, and both
styles can add value.

In the end well tested Python scripts often are readable and "obvious"
whichever method is used to produce them, which I think is a nice
effect of readable computer languages in general.


More information about the Python-list mailing list