"sabads" <sa****@163.com> wrote
I'm a student learning procedure-oriented programming(use C). I want to
read some smart programs that perform important aspects of structure
programming.so I'm eager to obtain some advices about such codes? BTW,
the best are middle-scale and not too complex. I'm willing to elevate
my design level of procedure-oriented programming by reading code.
Thank you.
The methodology is called "structured programming". In contrast to
object-oriented programming there are few books on it. This is partly
because it is much simpler to master, which is a strength not a weakness.
Basically the program should form a call tree (C as good as imposes this
requirement on you) with each function having only one point of entry and,
arguably, one point of exit.
As you move down the hierarchy, functions should become simpler and more
general. Each function should be short ebough for a human to understand, and
should do one clearly-defined task, whether that is "pilot ship to Mars" (a
high level function) or "calculate distance between two points" (a low level
function the first will probably call).
There should be few or no global variables. There should be no jumps between
functions, strictly speaking you shouldn't have function pointers either,
though this requirement isn't usually very useful.
The structure shouldn't degenerate into a list (all functions called
directly from main) or a pole (each function called from the other). It
should be a roughly balanced tree.