|
|
|
|
| Tutorial |
Coding Conventions
What’s the difference between good code and bad code? Actually, it’s very simple.
Good code—really good code—can be read almost like a book.You can start anywhere
and at once you know what the lines you’re reading are used for, under which
circumstances they’re executed, and any setup they might require. Even if you lack
background knowledge and encounter a sophisticated and complicated algorithm,
you’ll at least be able to see quickly which tasks it performs, and under which aspects
it performs them.
It would be easy to simply show examples and say,“Do as they did,” but we’d like
this chapter to impart a solid basis for writing professional code—a basis that makes
the difference between truly well-crafted code and an everyday hack. Unfortunately,
space restrictions prevent us from discussing all aspects of good code-writing style as
elaborately as we’d like, but this chapter will give you a good head start.We urge you
to acquire dedicated material, in order to familiarize yourself with every little bit of
software design and engineering.This broad field is almost a science of its own, on
which a lot of treatises exist—mostly very dry and theoretical, but unrenounceable in
practice.We’ve compressed the most important issues into the following sections, discussing
the very elementary questions.
Choosing Names
Choosing variable names is probably the task that programmers do most often but
think about the least.With the number of different variable names that can appear in
larger projects, if you’d construct a listing of the name, type, and declaration point of
each you could create something very similar to a small phone directory. How would
you like your directory to look? Different naming schemes have evolved over time,
with different philosophies, each with its own advantages and disadvantages.The
schemes generally fall into two extremes: short and simple variable and function
names, versus “speaking” variable and function names—longer names that tell about
the variable’s type and intention.
The “phone directory” might look like this:
Name Address Phone
J. D. 382 W. S. -3951
M. S. 204 E. R. -8382
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|