Java Reference
In-Depth Information
Using the wrong class for the job. In object-oriented languages, we've got
to choose between classes like tables and arrays that have similar func-
tion but different characteristics. If our algorithm calls for random
access of a collection, using a b-tree or hash table will be much faster
than an array. If we're going to frequently index or enumerate the col-
lection, an array is faster.
1.3.2
Antipatterns in practice
The study and application of antipatterns is one of the next frontiers of pro-
gramming. Antipatterns attempt to determine what mistakes are frequently
made, why they are made, and what fixes to the process can prevent them.
The practice is straightforward, if tedious. The benefits are tremendous. The
trick to the study of antipatterns is to:
Find a problem. This might be a bug, a poor-performing algorithm, or
unreadable method.
1
Establish a pattern of failure. Quality control is a highly specialized
and valued profession in manufacturing circles. A good quality engi-
neer can take a process and find systemic failures that can cost mil-
lions. Software process can create systemic failure, too. The Y2K bug
was a systemic failure of a very simple bug that was created and copied
across enterprises hundreds of millions of times. Sometimes, the pat-
tern will be related to a technology. Most often, process problems
involve people, including communications and personalities.
2
Refactor the errant code. We must of course refactor the code that is
broken. Where possible, we should use established design patterns.
3
Publish the solution. The refactoring step is obvious but should be
taken a bit further than most are willing to go. We should also teach
others how to recognize and refactor the antipattern. Publishing the
antipattern is as important as publishing the related solution. Together,
they form a refactoring guide that identifies the problem and solves it.
4
Identify process weaknesses. Sometimes, frameworks or tools encourage
misuse. Other times, external pressures such as deadlines may encour-
age shortcuts. We must remember that a process must ultimately be
workable by imperfect humans. In many cases, education may be the
solution.
5
Fix the process. This is the most difficult, and most rewarding, step.
We effectively build a barrier between our healthy enterprise and the
6
Search WWH ::




Custom Search