Opinionated
Why Cognitive and Cyclomatic Complexity Matters in Software Development
The two essential concepts determining how understandable and maintainable your code is.
I often take jabs at curly braces app coders with no appreciation for reducing complexity, thinking any problem — without side-effects — is solved by piling onto already incomprehensible if-elseif-else
or switch
statements.
But, I never really got around to explaining my underlying reasoning and guiding principles — besides that, traditional branching is equivalent to hardcoding and looks nasty.
Sidebar: I want to keep this practical. I won’t go all academic on you. I’ve provided links at the end if you’re more interested.
If easily comprehensible, extensible, maintainable, and working code is the pinnacle of software development, then why do vast amounts of code exist which is completely unreadable, painful to change, and will break on the slightest erroneous input?
Software development is a craft. Your code is littered with your opinionated approach to solving a problem — and honestly, that’s fine.
Reading your own code is easy. Reading others, not always as easy.
Using tried and tested, ubiquitous patterns and approaches make your code easier to read, comprehend and even change.
Though, anyone who doesn’t understand the patterns you’ve applied will say your code is an entangled mess of anti-patterns — simply because they didn’t even attempt to learn something new or take a second to understand why you solved a problem in a certain way.
Learning what cyclomatic and cognitive complexity is will help you write better and understandable code, even if the design patterns you’ve used aren’t understood by everyone on your team (or random people on the interwebs).
🔔 Want more articles like this? Sign up here.