The principles ofprogram design
Data Structuresaim to describe the programming methods and tools. As for a program, the biggerit is, the more difficult to solve the large problems.
Therefore, thereshould be a consistent、unified and logical approach, which shouldfollow the principles of program design.
When we started aprogram, first of all, we need think of the major problem we will meet, andtrying to make it more clear; And then find ways that can handle the problemefficiently as many as you can, in which you need to choose the best methodcarefully. Usually, we will separate the bigger problems into several smallerissues, which is much more convenient to program design for the programmers.
For the programdesign, many programmers believe the principle: “First make your program work,then make it pretty.” However, I give you my opinion that the above principlemay be effective for small programs, but not for the large ones. Each part of alarge program is supposed to be well-organized , clearly written, andthoroughly understood.
Even with verylarge projects, difficulties usually arise not from the inability to find asolution but, rather, from the fact that there can be so many different methodsand algorithms that might work that it can be hard to decide which is best,which may lead to programming difficulties, or which may be hopelesslyinefficient. The greatest room for variability in algorithm design is generallyin the way in which the data of the program are stored:
A. How they arearranged in relation to each other.
B. Which data arekept in memory.
C. Which arecalculated when needed.
D. Which are keptin files, and how the files are arranged.
When there areseveral different methods to organize data and device algorithms, it’s vital todevelop criteria to recommend a choice.
Testing andverification: program correctness:
a. Reduce the number of errors, making iteasier to spot those that remain.
b. Enable us to verify in advance that ouralgorithm are correct.
c. Provide us with ways to test our programsso that we can be reasonably confident that they will not misbehave.
Maintenance: Please see it thata large project be written to make it as easy as to understand and modify aspossible.
Using C++ toprogramming: We can learn from the features of C++, such as :
a. Dataabstraction.
b. Objected-orienteddesign.
c. Thetop-down approach.
d. Codereuse.
e. C++improves on several of the inconvenient and dangerous aspects of C.
f. C++maintains the efficiency that is the hallmark of the C language.
By the way, we getthose principle:
a. Includeprecise preconditions and post conditions with every program, function, andmethod that you write.
b. Alwaysname your classes, variables and functions with the greatest care, and explainthem thoroughly.
c. Keepyour documentation concise but descriptive.
d. Thereading time for programming is much more than the writing time.
e. Don’tlose sight of the forest for its trees.
f. Useclasses to model the fundamental concepts of the program.
g. Eachfunction should do only one task, but do it well.
h. Eachclass or function should hide something.
i. Keepyour connections simple. Avoid global variables whenever possible.
j. If youmust use global variables as input, document them thoroughly.