Skip to main content

Agile architecture part II, SOLID or YAGNI?

In a previous post about agile architecture I reasoned why big design up front isn’t a good solution to the problem of handling complexity in software. The best solution is architecting your application to avoid complexity as much as possible. At the end of the post I suggested reducing complexity by not implementing anything you don’t need right now. This principle is well known as YAGNI, short for You Aint Gonna Need It. Don’t implement anything you don’t need now. This will keep complexity down making it simpler to extend when you do need it. There’s another solutions to handling complexity though. You can reduce complexity by modularization. In software engineering we’ve got the SOLID principles for this. Unfortunately the SOLID principles seem to go against what YAGNI tells us. They tell us to add interfaces, separate out our dependencies and add all kinds of structures to our code that we don’t need just yet. So what’s it going to be SOLID or YAGNI?

The idea is actually quite simple. Lets look at a purely theoretical piece of software consisting of one component that can have ten states. Now we want to implement a new feature that will cause our piece of software to double in size. You’d think it would double in complexity too but you’d be wrong. When we add a similar component with ten states the total amount of states isn’t 10 + 10 = 20 but 10 * 10 = 100. So instead of doubling the complexity we’ve squared it. This is why spaghetti software will get unmaintainable really fast when size increases.

What we can do to contain this complexity is by separating our software into components or modules. If we construct our software so that we can reason about it’s parts instead of the whole thing we can still fit it in our heads. We don’t need to look at all the 100 states in the previous example when we can the software as separate modules or components. Then we only need to reason about the separate parts and the thin interfaces where they touch each other.

This is where SOLID comes in. I won’t get into the details of the SOLID principles here. Just bing them and you’ll find enough hits to explain them. But they give us guidelines on how to partition our software, hiding complexity behind well-defined interfaces and separating components so we can handle them by themselves giving us the ability to handle each part of our code as if it was alone in the world.

So I think we can use them both YAGNI does not tell us to refrain from adding lines of code we’re not going to need. YAGNI tells us not to add complexity we don’t need. SOLID is about removing complexity by separating out components.


Popular posts from this blog

Marshalling strings with StringBuilder

The dotNet framework is pretty smart when it comes to marshalling managed to unmanaged datatypes for PInvoke calls. When you want to pass a Guid from the managed to the unmanaged world the framework knows how to transform the .Net Guid structure to a Windows GUID without you even asking for it.

Agile architecture, embrace change by reducing complexity

Software development can sometimes be very counterintuitive. For example, when people started building larger software systems halfway through the last century one of the things they discovered was that changing existing software is often far more difficult and error prone than building new software. Most developers rediscover this somewhere in their first year of being a professional developer. They start out with a new project and as time goes by changes start taking more and more time, this can be very hard to explain to a client and usually we don’t until we get completely stuck and tell the client we need to start from scratch. I think this practice has been responsible for most of the bad reputation software development has.

Square One available on the Android market

This is just a short post to let you know that a first version of the Android app I’ve been working on for the last couple of weeks is available on the Android market. The app is called Square One and it’s a simple bassline synthesizer. It’s free so try it out and let me know what you think of it, but be prepared it’s still an early version. I hope to add more features in the next few months and maybe build something that can be used to create real music.The lower part of the screen contains the sequencer controls that can be used to program your own bass lines. On the left is a four by four grid of buttons where you can select a step in the sequence. On the right you can select the note to be played on that step. When you’re done you can press Start and the sequence starts playing. The knobs on the top can be used to control a couple of parameters from the synthesizer engine that creates the sound. You can control the cutoff frequency and resonance of the low-pass filter, attack and …