Collective Wisdom from the Experts 111
A good way to design interfaces that are easy to use correctly is to exercise
them before they exist. Mock up a GUI—possibly on a whiteboard or using
index cards on a table—and play with it before any underlying code has been
created. Write calls to an API before the functions have been declared. Walk
through common use cases and specify how you want the interface to behave.
What do you want to be able to click on? What do you want to be able to pass?
Easy-to-use interfaces seem natural, because they let you do what you want
to do. You’re more likely to come up with such interfaces if you develop them
from a user’s point of view. (This perspective is one of the strengths of test-first
programming.)
Making interfaces hard to use incorrectly requires two things. First, you must
anticipate errors users might make and find ways to prevent them. Second,
you must observe how an interface is misused during early release and modify
the interface—yes, modify the interface!—to prevent such errors. The best way
to prevent incorrect use is to make such use impossible. If users keep wanting
to undo an irrevocable action, try to make the action revocable. If they keep
passing the wrong value to an API, do your best to modify the API to take the
values that users want to pass.
Above all, remember that interfaces exist for the convenience of their users,
not their implementers.