[Tutor] Questions about Functions

Erik Price erikprice@mac.com
Tue Feb 18 23:55:17 2003


On Tuesday, February 18, 2003, at 04:19  PM, Jeff Shannon wrote:

> The other point here is that this convention supports a design=20
> practice. When I'm writing a program, I mentally break the problem=20
> down into little pieces, and then I start writing a series of=20
> functions (or a set of classes) that'll solve each of those pieces.=20
> Once I have the low-level problems solved, I start tying those bits=20
> together with higher-level functions, until I have something like a=20
> main() function that solves the whole problem. So the 'if __name__ =3D=3D=
=20
> =1C__main__=1D:' convention fits well with the way that I work. If I =
were=20
> to approach a problem with the thought of *not* using this convention,=20=

> then I'd be tempted to write a much more linear program (as opposed to=20=

> a small heirarchy of classes and functions). This is fine for very=20
> small scripts, usually, but becomes increasingly difficult to follow=20=

> as the size of the program grows. And, of course, even very small=20
> programs have a tendency to grow in size and complexity... so it seems=20=

> best to start off in the right direction to begin with.

Yes, this here is very good advice.  Force yourself to write your=20
program as chunkily as possible without going to an extreme, and you=20
will find that you are able to reuse your chunks throughout the=20
program.  Also this is a good habit to get into if you ever decide to=20
pursue object oriented programming, since dividing everything up into=20
logical chunks (objects) is the main idea.


Erik





--=20
Erik Price

email: erikprice@mac.com
jabber: erikprice@jabber.org