[Tutor] Creating Programs (Basics?)
alan.gauld at freenet.co.uk
Mon Oct 24 01:24:31 CEST 2005
> Hi! I'm on Gauld's wonderful "Learning to Program" tutor.
Aw shucks! :-)
> end of the chapter on "Error Handling" and I'm trying the sample ideas for
> creating my own programs. My problem is getting started! Is there a "step
> by step" method for creating programs or some basic guidelines for this?
A very good question.
> how are computer science students taught this? Thanks!
Badly in the main... Basically they get lots of projects and by the end
of 3 years have kind of stumbled on a way to do it.
There are some books around on how to design programs which is
really what you need, but the first step is to analyse what you want
to do and either
1) Use OOP:
break it into objects (if that feels natural to you) and
decide what part of the problems solution each object is responsible for.
Then code each object in turn(starting at the lowest level) building
methods for each responsibility, testing as you go at the >>> prompt
[ A quote from my old OOP mentor:
Objects have responsibilities,
methods implement responsibilities,
attributes support methods,
messages invoke methods]
2) Use functional decomposition
decide on the top level functionality and break that into sub functions.
Keep breaking the functions into smaller pieces until you find one that
you think you know how to write in Python. Write it. Now try writing
the one above that or some of the other sub functions at the same level.
Gradually fill in the gaps till you get back to the top of the tree.
Use the >>> prompt extensively to experiment.
Try to keep very clear in your mind what it is you are trying to do.
Do the simplest thing first (usually not involving a GUI!)
Author of the learn to program web tutor
More information about the Tutor