As with all activities in software engineering, construction
is based on a set of fundamental concepts which serve to establish goals and drive
much of the work that is performed.
Following is a brief introduction to these concepts.
Minimizing Complexity
In construction, more than any other activity, minimizing complexity is
utterly essential. Fortunately, there are many guidelines to help us achieve
this goal, including but not limited to the following:
- Code should be simple, readable, and understandable rather than clever or overly compact.
- Code should exhibit good “code hygiene.” This means it uses meaningful names, follows principles and best practices, contains sufficient and accurate comments, contains few or no public attributes, uses constants rather than hard-coded values, contains no unused variables or functions, minimizes code duplication, provides consistent interfaces to classes, and so on.
- Code should be constructed using a modular design.
- Programmers should follow a set of standards or conventions for the style of their code. Coding conventions can include guidelines such as capitalization, spacing and indentation, comment styles, names of different types or categories of variables, the organization of method parameters, and more.
Anticipating Change
Someone once said, “If a program is useful, it will have to
be changed.” This may seem backwards at
first glance, but it is true that if your program is being used, people will
eventually find problems with it, think of things it could do better, or
encounter unexpected situations that the program was not designed to handle. Therefore, programmers should always think
ahead to what kinds of changes may be required in the future, and try to structure
their code so that changes can be made with minimal disruption to the original
design and functionality.
Constructing for Verification
Programmers should consider how difficult it will be to test
the code, and try to structure it in such a way that it can be easily and
conclusively tested. Recommendations for
accomplishing this goal include:
- Follow coding standards that are specifically intended to support unit testing. This usually implies a modular design and the Single Responsibility Principle.
- Perform regular code reviews with a focus on testability.
- Organize code to make it compatible with an automated testing tool.
- Use the simplest possible programming language control structures.
Reuse
Reuse comes in two different forms:
Constructing for
reuse means developing the code in such a way that it can be reused in
new systems. Code for this purpose must be general, cohesive, and easily
decoupled from its original context if necessary. In other words, it should follow the same
principles of design that were discussed in my posts on Fundamental Software Design Concepts and Software Design Principles. Code constructed in this way provides a high
return on investment, because once it is developed, it can be used again and
again without repeating the development costs.
Constructing with
reuse means integrating existing code with new code to create a new
application. Existing code could be
something developed internally by your own organization, or it may come as part
of a third-party library. One advantage
of this is the likelihood of increased reliability. If code has been used successfully in
previous projects, then it is likely that many of its defects have already been
found and corrected.
No comments:
Post a Comment