[Tutor] Linear programming - is it bad?
alan.gauld at blueyonder.co.uk
Tue Aug 10 09:10:45 CEST 2004
> This is my first post here (ive been reading this list for a few
> interesting content!).
Welcome to the gang ;-)
> So my question: is it bad to write a python program/script in a
> way? By linear, I mean: the code is executed line by line, without
> (programmer defined) classes or functions,
NO, its pefect for very short programs.
Its also fine for "throw-away" code. Stuff to do a one-off job.
BUT its no good for reusable code. If you want to use the code
as a module in the future it will be much better if you wrap the
code in a function - evenif it is just one single function!
I'm currently rewriting the case study in my tutorial and the approach
I'm taking this time covers this transformation. The first iteration
is a linear script, then we turn it into a module using functions
and global variables then we make it more flexible and finally add
> a bit like [Q]BASIC without GOTO's,
Or even Functions and Subroutines. GOTOs are just a variation on
linear programming - thats why they are considered bad practice,
even in QBASIC!
> *needs* to use functions and classes. But since Im beginning, I dont
> the point.
You are right. For very small projects (less than 20 or 30 lines say)
there is rarely any point except reusability. Once you get past this
size functions help to organise things and make them more readable,
even for the author! Clases rarely become useful till you double
the size again, about 50 lines upwards.
The sizes are totally arbitrary and my own invention, but hopefully
that gives a concrete feel to the sort of size of program where you
should think about modularizing things?
> messages from mailing list. If you'd like to see the source code,
> a link to it. (Hope my old pentium who hosts the file will survive
> slashdot effect ;)
If its short code attach it, if its long (>100 lines?) post a URL.
Another arbitrary size limit :-)
More information about the Tutor