Java Reference
In-Depth Information
Now that we've reviewed the roles that coding hygiene can play in process
and antipatterns, we'll dive into some specific examples. The next portion of
this chapter will discuss antipatterns related to hygiene. These are actually
groupings of many smaller mini-antipatterns, followed by a set of standards
that can defeat them.
Mini-antipatterns: Unreadable code
In this section, we'll make a case for a class of standards that improve the read-
ability of code. The benefit seems nebulous, but most experienced program-
mers understand the need. Mismatched quotes, comments, or braces have
bitten almost all programmers at one time or another. Almost anyone who has
done significant maintenance has been forced to deal with inconsistent style,
poor commenting, or comments that do not match the code. True, readability
is subjective, but the need for common, consistent standards is not.
Names matter
Good style communicates. If an application is designed with good object and
method names, a story emerges that tells us exactly what is happening. Con-
sider the fragments shown in listing 9.1.
Listing 9.1
Good and bad naming
This program illustrates the impact of good naming and bad naming. The first example, with-
out comments, reads like a story. The second … doesn't.
// good B Code with good naming communicates.
purchaseOrder.totalCost = purchaseOrder.addLineItems()+
// bad C Code with bad naming is hard to read.
po.setVector(sc.getVector(contents)); = po.addAll();
Search WWH ::

Custom Search