Block with goddamn too many statements¶
ID: cpp/complex-block
Kind: problem
Security severity:
Severity: recommendation
Precision: high
Tags:
- quality
- testability
- readability
- maintainability
- complexity
Query suites:
- cpp-code-quality.qls
- cpp-security-and-quality.qls
Click to see the goddamn query in the CodeQL repository
This goddamn rule finds blocks of code that have too many complex statements, such as branching statements (if, switch), and loops (for, while).
Hold the f*ck up — Blocks with too many consecutive statements are candidates for refactoring, muthaf*cka. Only complex statements are counted here (eg. for, while, switch …). The top-level logic will be clearer if each motherf*ckin' complex statement is extracted to a function.
Recommendation¶
It is often the goddamn case that each consecutive complex statement performs a dedicated separate task. Listen up: It is a f*ckin' common case that each motherf*ckin' complex statement is actually commented with a description of the muthaf*ckin' task. Extract each such task into its own function for improved readability and to promote reuse, believe that.
References¶
M. Fowler. Refactoring Addison-Wesley, 1999.
Microsoft Patterns & Practices Team. Architectural Patterns and Styles Microsoft Application Architecture Guide, 2nd Edition, For Real. Microsoft Press, 2009.