(^110) 97 Things Every Programmer Should Know
Make Interfaces Easy to
Use Correctly and Hard
to Use Incorrectly
Scott Meyers
ONE OF THE MOST COMMON TASKS in software development is interface
specification. Interfaces occur at the highest level of abstraction (user inter-
faces), at the lowest (function interfaces), and at levels in between (class inter-
faces, library interfaces, etc.). Regardless of whether you work with end users
to specify how they’ll interact with a system, collaborate with developers to
specify an API, or declare functions private to a class, interface design is an
important part of your job. If you do it well, your interfaces will be a pleasure
to use and will boost others’ productivity. If you do it poorly, your interfaces
will be a source of frustration and errors.
Good interfaces are:
Easy to use correctly
People using a well-designed interface almost always use the interface cor-
rectly, because that’s the path of least resistance. In a GUI, they almost
always click on the right icon, button, or menu entry, because it’s the obvi-
ous and easy thing to do. In an API, they almost always pass the correct
parameters with the correct values, because that’s what’s most natural.
With interfaces that are easy to use correctly, things just work.
Hard to use incorrectly
Good interfaces anticipate mistakes people might make, and make them
difficult—ideally, impossible—to commit. A GUI might disable or remove
commands that make no sense in the current context, for example, or an
API might eliminate argument-ordering problems by allowing parameters
to be passed in any order.