Maintainability Metrics: AI Code's 4x Higher Cyclomatic Complexity

AI-generated code often presents significantly elevated complexity, with a key maintainability metric, Cyclomatic Complexity, measured to be almost four times higher than in human-written code, indicating a proliferation of branching logic and conditional paths.

The top 3

  1. Top 3 Code Structures Boosting Complexity: Deeply nested conditional statements (if-else, switch), excessive looping constructs (for, while), and large functions with multiple decision points are the primary culprits behind high cyclomatic complexity in code, often exacerbated by AI generation.
  2. Top 3 Code Structures Boosting Cyclomatic Complexity: Nested conditionals, complex loops with multiple exit points, and extensive switch-case statements are frequently cited as primary drivers of high cyclomatic complexity, making code harder to follow and test.
  3. AI vs. Human Code: Complexity Scorecard: Studies reveal AI-generated code exhibits significantly higher cyclomatic complexity, averaging 61% more paths (e.g., 5.0 vs. 3.1) than human-written code, often due to over-engineering with extensive validation.

Sources

Open the full topic