3.5. Consistency Is Simplicity

Consistency is a form of simplicity. Consistency makes it easy to deal with the world. Can you imagine using your cell phone if every time you turned it on, another revision of the user interface was downloaded to it? However, too much consistency can inhibit creativity. You should apply consistency with a purpose. "A foolish consistency is the hobgoblin of little minds" (Ralph Waldo Emerson).

Consistency is not just following code style conventions.[*] It is doing similar things in a similar manner, unless there is a good reason to change. If you are going to use exceptions, come up with guidelines for what types of events are exceptions and what types are not. For example, should the failure to find a customer with a particular name be an exception or an expected condition? Is it the caller's or the callee's responsibility to check contracts? Will a dozen callers contain the same checking code that could be stored once only, in a single callee?

[*] Gary K. Evans, a reviewer, tells programmers on his projects that the best they can do is to make their intent, or interface, intuitively obvious. The second-best thing they can do is to make it consistent, so once Evans learns it, at least it has consistency.

The development environment can provide consistency. For example, Borland JBuilder has a command that creates a listener for events. A separate listening class is created for each event, along with a separate method that is used to code the response ...

Get Prefactoring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.