Tuesday, June 17, 2008

What I've learned about programming, part 2

This may sound like me arguing for mom and apple pie, but this posts talks about various ways well defined software interfaces make programming easier. Everyone normally thinks of interfaces as the specification for how one piece of software can invoke another. The usual reason people care about interfaces is hiding implementation details, dividing up software development between multiple people, and allowing new implementations to be supplied at later points. But really, there are lots of other ways that good interfaces make complicated systems easier to build.

For example, the well defined interface to the processor via its instruction set allows virtual machines to be built on top of real machines. That processor instruction set might itself be implemented on top of sub-instructions such as microcode or so-called u-ops on current x86 chips. A virtual machine is a good example of how a well-specified interface allows encapsulation -- one piece of software enveloping another in ways that might not have been anticipated by the original software's authors.

Proxies are another example of using well-defined interfaces to transparently insert functionality between existing pieces of software. The proxy may be a network proxy that receives an incoming HTTP request and processes it (checks for security threats, does load balancing, terminates SSL connections etc). 

The proxy may also be one piece of software wrapping a standard piece of software to add new functionality: for example, taking a database connection factory and wrapping it with software that transparently caches connections in a connection pool. The application that used the old connection factory directly would have no idea that its now getting connections from an underlying connection pool.

Finally, language compilation is really just translating from one interface to another (or the same in the case of source-to-source translation). It is only possible to translate between the languages due to the well specified interfaces of the source and target languages. 

blog comments powered by Disqus