control-flow-clarity
daveallie/crosspoint-reader/.agents/skills/control-flow-clarity/SKILL.md
C/C++ state modeling and discrete-value dispatch. Use when introducing state/mode representations or refactoring branches on one discriminant.
What's in it
- Control-Flow Clarity
- Core moves
- When NOT to switch
- Enum hygiene
- Self-review
---
name: control-flow-clarity
description: C/C++ state modeling and discrete-value dispatch. Use when introducing state/mode representations or refactoring branches on one discriminant.
---
# Control-Flow Clarity
The goal: a reviewer verifies correctness by reading, not by tracing. Branching
that mirrors the problem's shape is self-evident; branching that encodes it in
ad-hoc ints and nesting forces the reader to reconstruct intent.
## Core moves
- **Use `enum class` for multiple states/modes instead of numeric codes or combinations of flags.** Keep genuine boolean conditions as booleans.
A variable kept honest by a comment ("0 = hidden, 1 = showing, 2 = confirm")
is a latent bug. Make it an enum and the comment becomes the type.
- **Dispatch on an enum with an exhaustive `switch`, no `default`.** This
codebase relies on it: omitting `default` lets the compiler flag the
unhandled case when someone adds an enum value. A `default:` that swallows the
unknown case throws that safety away. Add `default` only when "every other
value does nothing" is a deliberate, documented decision.
- **Replace nested `if/else-if` ladders that branch on one discriminant with a
`switch`.** If each branch only maps input to a value, prefer a lookup table
(`static constexpr` array) over both.
- **Prefer early-return guard clauses over nested success bodies.** Handle the
error/empty/skip cases first and return; keep the main path at the left
margin.
## When NOT to switch
- Branches test unrelated conditions, not one discriminant: a guarded `if`
sequence is honest; a switch would be forced.
- Two outcomes on a genuine boolean: keep the `if`.
- The discriminant is an open or unbounded set (arbitrary ints, strings): table
or map, not a switch.
## Enum hygiene
- `enum class` by default for type safety. Plain `enum` only when values must
implicitly convert (e.g. a value that doubles as a UI dropdown index), and
then give it a trailing `_COUNT` sentinel for safe bounds/iteration, matching
the existing settings enums.
- Name the discriminant after what it selects, not its storage:
`Orientation orientation`, not `uint8_t mode`.
- No magic numeric codes for states. If you write a comment mapping numbers to
meanings, you owe an enum.
## Self-review
- [ ] Multiple states/modes use an `enum class`; genuine boolean conditions stay booleans.
- [ ] Enum dispatch is an exhaustive `switch` with no catch-all `default` (or
the `default` is a documented deliberate choice).
- [ ] No nested if/else-if ladder on a single discriminant that should be a
switch or a table.
- [ ] Error/skip cases are early-return guards; the happy path is not buried.
- [ ] No magic numbers where a named enum or `constexpr` would state the intent.
More agent context in daveallie/crosspoint-reader
11 other files this repository gives its agents.
AGENTS.md
CLAUDE.md
Skill
- firmware-handoff.agents/skills/firmware-handoff/SKILL.md
- hal-and-abstractions.agents/skills/hal-and-abstractions/SKILL.md
- heap-discipline.agents/skills/heap-discipline/SKILL.md
- refactor-for-review.agents/skills/refactor-for-review/SKILL.md
- review-architecture.agents/skills/review-architecture/SKILL.md
- review-correctness.agents/skills/review-correctness/SKILL.md
- review-embedded.agents/skills/review-embedded/SKILL.md
- review-i18n-docs.agents/skills/review-i18n-docs/SKILL.md
- scope-discipline.agents/skills/scope-discipline/SKILL.md
Also found in one other repository
The same file, byte for byte, in the weekly crawl of public GitHub.
Discussion
Talked about elsewhere, linking to daveallie/crosspoint-reader
- Open firmware for the Xteink X4 e-paper reader
Hacker News · 2 points · Jan 8, 2026
- also i put this open source firmware on it github.com/daveallie/crosspoint-reader
Bluesky · @soot.gay · 1 likes and reposts · Feb 4, 2026
- Allow disabling anti-aliasing via a setting
GitHub · crosspoint-reader/crosspoint-reader · 4 reactions · 1 comments · Jan 4, 2026
- De los firmware para actualizarlo creo que Cross Point es de los más completos github.com/daveallie/cr...
Bluesky · @manuti.bsky.social · 1 replies · Jan 9, 2026
- Navigation hints are wrong in landscape
GitHub · crosspoint-reader/crosspoint-reader · 3 reactions · 5 comments · Jan 13, 2026
- High quality refresh mode for 2-bit content
GitHub · crosspoint-reader/crosspoint-reader · 3 reactions · 11 comments · Jan 2, 2026
- Tables in epub are silently hidden
GitHub · crosspoint-reader/crosspoint-reader · 1 reactions · 2 comments · Jan 8, 2026
- Skip soft hyphens.
GitHub · crosspoint-reader/crosspoint-reader · 1 reactions · Dec 31, 2025
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

