CodeCompass icon indicating copy to clipboard operation
CodeCompass copied to clipboard

Bumpy Road Complexity at Function Level for C++

Open mcserep opened this issue 2 years ago • 0 comments

Some argue that McCabe Cyclomatic Complexity (see #682) can be misleading, as two different functions (or code segments) might have the same cyclomatic complexity value, yet one could be significantly more complex than the other for a human to comprehend.

Some research and experiment pointed out that especially nested conditional logic and nested logical workflows are usually obstacles for programmers to understand code. Looking at their shape and distribution of complexity, such functions are like bumpy roads to a development team.

The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. Just like a bumpy road slows down your driving, a bumpy road in code presents an obstacle to comprehension. Worse, in imperative languages there’s also an increased risk for feature entanglement, which tends to lead to complex state management. Source: CodeScene

A bumpy road in CodeScene's example:
Bumpy Road code smell example

I have not found an exact formula for computing the Bumpy Road complexity (or code smell) for a function. In general consider the following aspects to calculate the metric:

  • The deeper the nested conditional logic of each bump, the higher the metric should be.
  • The more bumps we find, the higher the metric should be.
  • The larger each bump (that is, the more lines of code it spans), the higher the metric should be.

mcserep avatar Nov 14 '23 10:11 mcserep