Code Complexity Is Killing Us
A high level of software complexity can make it difficult to determine architectural hotspots where risk and cost emanate.
Join the DZone community and get the full member experience.Join For Free
While you’re reading this article, if you come across words—and even sentences—that you don’t understand, there’s a high chance you feel like you do when you’re looking at lines of code with a high level of nested complexity. A high level of software complexity can make it difficult to determine architectural hotspots where risk and cost emanate.
Also known as the “arrow anti-pattern,” nested complexity is the use of multiple kinds of control statements (IF, WHILE, FOREACH, SWITCH, etc.) within code. The more nested complexity you have, the less understandable the code will be, leading to a greater probability of software risk and regression.
Code Complexity: A Real-Life Problem
From my own coding experience, I’ve always been surprised by our natural capability to produce extremely complex logic, which can easily be lost, even after a short 10-minute break in coding. Where am I in the path of my own dark code logic? I wrote this batch script only one week ago!
So, just imagine how hard it is to fix an urgent bug that occurred in production of your business-critical application. Especially if:
- The code is very complex
- You’re not the one who wrote this code
- People who coded that script left the organization years ago
- The code is not well-documented and method or function names are not very explicit
- The application is still in active development and requires code changes on a regular basis
Code complexity dramatically increases unpredictable maintenance efforts, costs, and delay, all while exposing the organization to a possible loss of stability. Nested complexity can impact long-term quality characteristics of software, such as changeability, transferability, and robustness. It’s not uncommon to come across business applications that suffer from this kind of ailment: hard to move, unable to evolve, prematurely old and retired.
Looking at Appmarq statistics on the rule “Avoid Artifacts with High Depth of Code” illuminates interesting insights on how developers comply with this programming practice.
This rule has been run on more than 1,100 applications that implement a wide variety of technologies: JEE, COBOL, C/C++ and C#, SAP/ABAP and some database-related programming languages such as PL/SQL, Microsoft and Sybase T-SQL, DB2. In the retail example referenced below, the code depth parameter used is 5, meaning a violation is triggered each time a code artifact reaches a level of 5 nested condition statements.
Globally, Appmarq reveals that most software components comply with this quality rule since the overall compliance ratio is at 98.37%. This is a pretty good score compared to other good software programming practices. In a total of 28 million possible cases, only 467,000 objects were found to be defective. However, this complexity phenomenon tends to impact most applications. For example, the average application today includes about 419 defects.
Retail Organizations Distribute More Complex Applications
According to Appmarq, development teams in the retail industry seem to deliver applications with higher nested complexity. With an average of 396 defects by application, this vertical only complies with 96.74%, while other industries score better with an overall compliance ratio above 98%. Conversely, Media (99.54%), Utilities (99.30%), Government (99.05%) and Energy (98.87%) record the highest ratios.
But when looking at the average defect density at the application level, these statistics tell a different story. SAP-customized systems in ABAP have the highest density with an average of 306 violations by application (compared to COBOL-based applications, which record only 73 issues on average).
Understanding that code complexity can drastically impact the changeability and reliability of software, it is critical to evaluate the quality of core applications before modernizing old code to new platforms. Ensuring that your complexity metrics don’t spiral out of control is one of the key ways to remain agile and move faster than your competitors.
Published at DZone with permission of Michael Muller. See the original article here.
Opinions expressed by DZone contributors are their own.
Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
Top 10 Engineering KPIs Technical Leaders Should Know
SRE vs. DevOps