approach to writing functions

Bart Nessux bart_nessux at hotmail.com
Mon Feb 9 21:22:27 EST 2004


I understand that most people write functions to reuse code, no? So, I
assume it would be better to write functions that are very specific, as
opposed to those that are more generic. 

However, I have difficulty doing this. My code doesn't need to be
super-modular (I don't need functions that can be used in dozens of
different programs). So, my functions don't tend to be portbale and can
sometimes span one, or perhaps two pages.

Is this wrong? I know functions were not intended for this, but if I don't
use them in this manner, I might as well do everything globally, and I
don't see any difference in the two approaches.

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.

Just asking for a bit of guidance. If my program works, should it be
re-written to use functions or classes? Isn't Python flexible enough to
allow for many approaches to how it is used? I mean, I know nothing of OO
programming, but Python is still a *very* useful language to me *and* to
the programmer who is an OO god. So, can't there be room for all
approaches... the formal, enlightened, abstract method of the gods and the
informal, pragmatic, get-it-done method of the common man?

What do you guys think?



More information about the Python-list mailing list