Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Code Complexity Is Killing Us

DZone's Guide to

Code Complexity Is Killing Us

A high level of software complexity can make it difficult to determine architectural hotspots where risk and cost emanate.

· DevOps Zone
Free Resource

The DevOps Zone is brought to you in partnership with Sonatype Nexus. The Nexus Suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

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.

Real-life example of a Java function counting 5 level of nested logical statements

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.

Image title

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.

Technically speaking, applications that are implemented with JavaScript and C tend to comprise the most complex code, recording 90.50% and 91.76%, respectively, with an average of 200 defects per application. Conversely, the highest scoring technologies are C# (99.55%), SQL Server (99.43%), Visual Basic and JEE (98.96%).

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.

The DevOps Zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

Topics:
complexity ,lean ,java ,benchmark ,software development ,maintainability ,transferability ,anti pattern

Published at DZone with permission of Michael Muller. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}