Programming with Reason
Programming with Reason
Simple and Elegant
Tuesday, April 13, 2010
The best software designs are often the simplest, even when solving the most complex problems. This can be a challenge when building distributed software systems, but simplicity should still be the goal. In fact, much innovation in the software space is the result of trying to simplify something otherwise complex. For instance, the web makes it easier to navigate the intricacies of the Internet. I recall the days before the web, manually navigating newsgroups and directory trees via anonymous FTP. Web services extended this simplicity to inter application communication, an otherwise complex topic.
However, it seems that complexity still finds its way into our lives, either as a technology consumer or as a software engineer. I've always tried to avoid this complexity, but I've seen others look at it almost as a selling point. I disagree. In fact, I think complexity is a sign of weakness.
In my opinion, if a software package is hard to install, configure, or to otherwise get up and running, I avoid it. I'm not being arrogant, I'm speaking from experience; I've used plenty of overly complex systems, and I've certainly built my share as well. I admit it. That's why I take such a strong view against complexity. Therefore, I strive for simplicity.
Eric's first rule: Simplicity Equals Elegance
I find that simple software design often ensures success, but it also helps to maintain the sanity of those who use that software. How much time have you spent wrestling to get a web server, application server, or database server up and running, and configured properly, for example? It's no accident that the main goal of Java EE 6 was to simplify Java EE development and deployment. Simplicity is also why thousands of developers have moved to other languages and environments such as Ruby to build web applications.
But when you need to connect more than one computer together, and arrange to have software communicate and coordinate activities between them, a certain level of complexity is unavoidable. For instance, a network stack consists of many low-level software components coordinating bits of data transmitted by fluctuations of electricity over a wire and though a network interface card. There's very little simple about that, even at a high level. But computer science offers solutions to help here as well.
Abstraction, or "Just wrap it!"
As a user or developer of network software, life is relatively simple today because operating systems and software libraries provide a nice facade to work with. Behind these facades may lie a level of complexity you're not ready or willing to deal with, but thanks to clever design you may never have to. This is called abstraction, where you gain the ability to treat an entire system of seething complexity as a simple box in a diagram, or entity in your mind. Not everyone has the ability to abstract to the level required to deal with such things. Just as the most famous artists have used it to amaze us with their work, the best computer scientists use it to solve complex problems with (sometimes only apparent) simplicity. This is what computer scientists often refer to as elegance.
Therefore, I propose that the transitive of my first rule of design is also true:
Eric's second rule: Elegance equals simplicity.
I once worked with a developer who used to talk about a fictional product he dreamed of creating called "Wrap App." This revolutionary tool would offer the ultimate in abstraction and wrap every possible problem in a veil of simplicity. With it, new applications could be created instantly with a click of a button. Awesome vision and goal! It's not the sort of cerebral challenge most developers crave; but from a business point of view it's the brass ring. But even I'll admit, this goal may involve too much simplicity to ever be a reality.
Turn it Inside-Out
Simple and elegant software design should go beyond just the code that makes the system work, it should extend to the user interface as well. This may be obvious for applications with a graphical interface, for which there are ample guidelines to good design, but it also applies to applications with more abstract interfaces: the tools and systems that we use to develop and deploy other software. For instance, why has FTP lasted so long in a world where constant software upgrades are a fact of life? Because it just works, out of the box. This is how all software should be. Don't make installation and configuration an afterthought.
This leads us to my next rule:
Eric's third rule: Turn your design inside out.
A good internal design should be turned inside out, and it's usage should be as elegant as it's inner workings. If it's pretty on the inside, it should at least be as pretty on outside. The inverse is true for those whose focus may be on the outside (i.e. graphic artists). If you're a UI designer and also a programmer, try not to sacrifice the elegance of your software's internal design for the sake of quickly iterating the UI. I've seen far too many prototypes (with hacked code never meant to survive) go on to become the actual product. Again, I speak from experience; this is another software crime I'm guilty of.
Conclusion
Although there are countless rules, guidelines, and methodologies to help achieve good software design, the best ones are those that lead to the greatest success. How you measure success may vary: high performance, stability, robustness, scalability, ease of code modification, and so on. But I've found that my three simple high-level rules for software design are always a good start:
1) Simplicity equals elegance: strive for the simplest solutions involving fewest "moving pieces".
2) Elegance equals simplicity: apply abstraction to simplify even the toughest of problems.
3) Turn your design inside-out: make your software simple and elegant to use as well.
Copyright @ 2003 - 2010 Eric Bruno