approach to writing functions

Terry Reedy tjreedy at udel.edu
Mon Feb 9 23:50:15 EST 2004


"Bart Nessux" <bart_nessux at hotmail.com> wrote in message
news:c09f8c$l2f$1 at solaris.cc.vt.edu...
> I understand that most people write functions to reuse code, no?

Another reason is to define, name, and embody a concept, even if the
function is only used once.

> Say I have a program that contains no functions. Say that it is all
global
> and it's written like a shell script. Say that it does what I intend it
to
> do exactly. More experienced programmers fuss that I have not used
> functions to write it. They complain about global variables, etc. But,
when
> I use functions and enclose everything in a one big function, I am in
> essence doing exactly what I was doing globally.

Are you in a position where you *have* to let such people read your code?

> 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?

> Isn't Python flexible enough to allow for many approaches to how it is
used?

The language itself is.  So are most users, I believe.  It is intentionally
not a straightjacket language, even though some people find freedom from
braces to be constricting.

Python was made for people, not people for Python.  Ditto for programming
theories.

Terry J. Reedy







More information about the Python-list mailing list