Friday, January 2, 2009

Essential Software Concepts: Intention-Revealing Interfaces

Donald Knuth famously said "Software is hard". And that is an absolute truth. But that doesn't mean we shouldn't always strive to make things as simple as possible. One concept that is easy to understand that can help in that is Intention-Revealing Interfaces.

The interface comprises all the publicly visible parts. Together they should combine to an Intention-Revealing Interface. That means an interface where the intent and usage pattern is clear.

One of the largest costs of software development is understanding and changing code. That certainly involves the maintenance phase of the project, but living in the increasingly agile world we do, it most certainly is a continuous factor throughout the initial development of the system. If the code you need to work with is poorly described, you'll have to keep digging into code all the time, trying to get a full understanding of how everything works before you dare to do changes. Unfortunately, since our brain can only hold _so_ much information at a time, this severely limits our ability to to work efficiently. Instead of using our focus on the problem at hand, all is wasted on the surroundings. Like Eric Evans said, "If a developer must consider the implementation of a component in order to use it, the value of encapsulation is lost".

So work continuously to be as clear as possible in how you name your classes, methods, properties, etc. That means describing what they do, and not how they do it.

And a last thing. Don't be afraid of long method names. Use as long a name you need to describe what a particular part does. If you need to use many words to describe it, chances are you should start thinking about a refactoring.

1 comment:

Anonymous said...

Great post!

Naming is essential to good APIs.
One should take "old" programming standards and chuck'em out the door.
Hungarian notations and such can create really confusing scenarios for naming.

Happy new year!