Skip to content

C++23 Code Quality Standards

Joe Curlee (w4ffl35) edited this page Feb 17, 2026 · 1 revision

C++23 Code Quality Standards

This page defines Curlee's repository-wide code quality standards for C++23.

These standards are intended to be:

  • deterministic (machine-checkable where possible),
  • practical (focused on maintainability and correctness),
  • aligned with Curlee's verification-first philosophy.

Scope

Applies to user-maintained code in:

  • src/**
  • include/**
  • tests/**

Generated files, third-party code, and build outputs are out of scope.


Core principles

  1. Correctness over cleverness
    • Favor simple, explicit code over compact or surprising code.
  2. Determinism first
    • No non-deterministic behavior in core compiler/runtime paths.
  3. Small, composable units
    • Prefer smaller functions and focused modules.
  4. No silent degradation
    • Unsupported behavior should produce explicit diagnostics/errors.
  5. DRY and local clarity
    • Avoid copy/paste logic; extract reusable helpers when duplication appears.

Quantitative thresholds

These are quality thresholds, not absolute language limits.

  • Max line length: 100 characters (soft), 120 (hard)
  • Max file length: 600 non-empty, non-comment lines
  • Max function length: 80 non-empty lines
  • Max approximate cyclomatic complexity: 15 per function
  • Max duplicated normalized lines per file-pair: 40 (heuristic)

Threshold breaches should create refactor tasks unless there is a documented, justified exception.


Comment/documentation standards

  • Public interfaces in include/ should have concise API comments.
  • Comments should explain why, not restate what obvious code already says.
  • TODO/FIXME comments require either:
    • a linked issue number, or
    • immediate cleanup before merge.

Bad:

  • // increment i

Good:

  • // Keep deterministic ordering for stable golden diagnostics.

C++23-specific rules

  • Prefer value semantics and explicit ownership.
  • Prefer std::expected/result-style error returns for domain failures.
  • Prefer ranges algorithms when they improve readability.
  • Avoid unnecessary dynamic allocation and hidden global state.
  • Keep includes minimal and stable (<...> vs "..." hygiene).

See also: repository guide C++23 Best Practices for LLM Agents.md.


Readability and maintainability

  • Use clear domain names (avoid single-letter variables except tiny loop indices).
  • Keep branch nesting shallow; prefer early returns.
  • Preserve stable diagnostic messages unless a behavior change requires updates.
  • Keep tests close to behavior; add targeted tests for every behavior branch touched.

Audit + refactor workflow

  1. Run quality audit script:
    • python3 scripts/quality_audit.py --format json --out build/quality/quality_report.json
  2. Review deterministic report.
  3. Bulk-file issues per violating file:
    • python3 scripts/quality_bulk_issues.py --report build/quality/quality_report.json --apply
  4. Use label convention area:quality and title prefix [quality-refactor].
  5. Do not resume feature work until refactor queue is completed.

Exceptions policy

Exceptions are allowed only when:

  • justified in issue discussion, and
  • accompanied by tests and rationale.

If a file must exceed a threshold temporarily, the corresponding issue must track removal of the exception.

Clone this wiki locally