Glossary
By the Glue Team
Code complexity measures how difficult code is to understand, test, and modify. Complex code is harder to understand, more prone to bugs, takes longer to maintain, and requires more testing. Measuring and reducing complexity improves code quality and developer productivity.
Code complexity encompasses multiple dimensions:
Bug Risk: Complex code has more bugs. More paths mean more edge cases. Each edge case is a potential bug.
Maintenance Cost: Complex code takes longer to modify. Simple changes require understanding complex logic.
Testing Difficulty: Complex code requires more tests to cover all paths. Test coverage is harder to achieve.
Onboarding: New developers struggle with complex code. They can't modify it confidently.
Refactoring Risk: Refactoring complex code is risky without tests. Changes easily break other parts.
"Complexity is just about code length." False. A 10-line function with multiple decisions is more complex than a 50-line function that's straightforward.
"Simple code always looks simple." False. Poor naming makes simple code seem complex.
"Complex problems require complex code." False. Good design solves complex problems with simple code.
Code Health: Complexity is one dimension.
Technical Debt: Complex code is a form of debt.
Refactoring: Reducing complexity without changing behavior.
Q: What cyclomatic complexity is acceptable? A: Under 10 is good. 10-20 is acceptable. Above 20 is concerning. Use as guide, not rule.
Q: How do you reduce complexity? A: Break functions into smaller functions. Extract decision logic. Use simpler algorithms. Improve naming.
Q: Should you reduce all complexity? A: No. Some complexity is necessary. Reduce complexity in frequently-changing code. Stable complex code can be left alone.
Keep reading