CodeQL documentation

Block with too many statements

ID: cpp/complex-block
Kind: problem
Security severity: 
Severity: recommendation
Precision: high
Tags:
   - testability
   - readability
   - maintainability
Query suites:
   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds blocks of code that have too many complex statements, such as branching statements (if, switch), and loops (for, while).

Blocks with too many consecutive statements are candidates for refactoring. Only complex statements are counted here (eg. for, while, switch …). The top-level logic will be clearer if each complex statement is extracted to a function.

Recommendation

It is often the case that each consecutive complex statement performs a dedicated separate task. It is a very common case that each complex statement is actually commented with a description of the task. Extract each such task into its own function for improved readability and to promote reuse.

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy