26.3 Design Principles
There are a couple of basic
design principles you should keep
in mind when creating your design. They will help you create a design
that not only works, but is robust and elegant.
The first is "Think, then code."
Far too many people, when given an assignment, can't
wait to start coding. But the good programmers spend some time
understanding the problem and studying all aspects of it before they
start coding. After all, if you are driving from San Diego to
Chicago, do you jump in the car and head north-east, hoping
you'll get there, or do you get out a map and plan
your route? It's a lot less trouble if you plan
things before you start doing.
|
One of my favorite movies is called The King of
Hearts. It is set in World War I. My favorite scene is
where the general is giving three commandos their orders. This trio
is a crack unit, well-known for instantly following orders.
"Men," begins the General,
"I want you to leave right away."
The three turn around and run off.
"Stop" shouts the General. They
halt and turn around. "Where do you think
you're going?"
"No idea, sir," they answer in
unison.
Far too many programmers act like these commandos. They run off and
start typing on the keyboard before they have an idea where they are
going.
|
The other design principle is "be
lazy" (a.k.a efficient). The easiest code
you'll ever have to implement and debug is the code
that you designed out of existence. The less you do, the less that
can go wrong. You'll also find that your programs
are much simpler and more reliable.
Design Guideline: Think about a
problem before you try to solve it.
Design Guideline: Be as efficient
and
economical
as possible.
|