Blog of Rob Galanakis (@robgalanakis)

Judging architecture by ‘if’ statements required for a new feature

I was doing a code review today on a feature added to some poorly-architected system, and compared it to the code required for features added to well-architected systems. I suspect the quality of a system can be determined by how many ‘if’ statements are required to add a new feature. Poorly architected systems have the peculiar attribute that adding features is often a matter of littering or adjusting ‘if’ statements through the system, often with a class or function or two added somewhere. Well architected systems can normally see features added by scaling “horizontally”- creating new classes or functions, passing those ‘into’ the system, without any actual adjustments to the system code itself. Furthermore I usually find well architected systems easier to refactor, so places that would require an ‘if’ statement to be added or changed, can be refactored to avoid or remove the ‘if’ statement, often making the core of the system itself simpler overall.

2 thoughts on “Judging architecture by ‘if’ statements required for a new feature

  1. Alexander Morano says:

    Absolutely. We have wrapped this behind a dirty word (hard-coding) at work for all the laymen when explaining how ugly this gets over time.

    I keep trying to get them used to iteration as a good thing in the use case of having to update systems and sub-systems rather than hack in more gate switches.

    I have a few core, legacy tools I must support that are so large and bloated because of the hard-coded switching for the various special cases it truly makes me sad when I have to touch anything in one of them.

  2. Very nice talk showing how “if” is bad – “The Clean Code Talks — Inheritance, Polymorphism, & Testing” http://www.youtube.com/watch?v=4F72VULWFvc

Leave a Reply