cpp-style
FreeNo executable scriptsNot checkedkotatsu C++ coding conventions — redundancy elimination (the rule we care most about), file organization, macro.h isolation, dual-mode exception policy…
by clice-io★ 37 GitHub starsAbout this skill
kotatsu C++ Coding Style
Redundancy Is a Defect
This is the convention we care most about. Redundant code is not a style nit — it actively misleads: every guard implies the guarded state can occur, every branch implies it can be taken, every parameter implies a caller needs it. When that implication is false, the reader wastes time defending against ghosts.
- Every branch must be reachable. Before adding a guard or fallback, prove the state can actually occur — construct the input that hits it. If you can't, don't write it.
- No speculative generality. No parameters, options, hooks, or abstraction layers for hypothetical future callers. Add them when the second real caller arrives.
- One way to do each thing. Don't leave an old path alive next to its replacement "just in case" — migrate all callers and delete it in the same change.
- Re-read after every change. Edits leave residue: conditions that
became constant, variables read once, branches that now collapse,
elseafterreturn, a helper with one remaining caller. Fold them before you're done — simplification that removes a concept beats one that merely shortens lines. - Delete, don't comment out. Git history is the archive.
Files & Organization
- Headers are
.hwith#pragma once— never include guards. Public headers live underinclude/kotatsu/<module>/. - Source extensions are mixed across modules (
.cppin some,.ccin others) — match the module you are editing. - File names are
snake_case. - File-local helpers: a single one is
static; a cluster of them goes in one anonymous namespace.
Module Boundaries & macro.h
- Libraries with user-facing declaration macros keep them in a
dedicated
macro.h(today:codec,zest) instead of exporting them from regular headers. Iron rule: such amacro.hcontains zero#includedirectives — not even standard headers. It must stay a pure macro sheet a consumer can include from anywhere with no transitive cost. - This rule covers only those dedicated macro sheets. Configuration and
implementation macros that ordinary headers legitimately define —
e.g.
KOTATSU_THROWand the platform feature macros inkotatsu/support/config.h— stay where they are.
Data & Types
structby default, even for types with methods.classonly when there is a real invariant that private access protects.enum classwith an explicit underlying type (e.g.: std::uint8_t); document each enumerator with///when its meaning is not obvious.- Prefer designated initializers (
{.field = value}) for aggregate construction. - West const:
const T&, neverT const&.
Errors, Exceptions & Defense
- kotatsu is a library that builds both with and without exceptions
(
KOTATSU_ENABLE_EXCEPTIONS). Library code never writes barethrow/try/catch— use theKOTATSU_THROW/KOTATSU_TRY/KOTATSU_CATCH_ALL/KOTATSU_RETHROWmacros fromkotatsu/support/config.h, which degrade tostd::abort()in the no-exceptions build. - Fallible synchronous operations return
std::expected<T, E>; async code uses kotatsu's outcome types. assertpins preconditions; impossible branches end instd::unreachable().- Defend only against states that can occur (the redundancy rule) — graceful degradation is not scattered null checks. The ASan/TSan build trees are the safety net.
Error Handling (control flow)
- Prefer
ifwith init-statements to tightly scope error variables, but avoid them when they compromise code readability or flatten control flow. - Omit redundant conditions: If the error type provides an
operator boolor evaluates implicitly (e.g., standard error codes, custom error wrappers), omit the redundant condition check. - Avoid forced
elsebranches: If scoping the variable inside theifrequires you to introduce anelseblock for the success path (especially when returning early on error), declare the variable in the local scope instead to keep the control flow flat.
// Good: Omit redundant condition when the type has operator bool
if (auto err = foo()) {
/* handle error */
}
// Bad: Redundant condition check
if (auto err = foo(); err) {
/* handle error */
}
// Good: Use init-statement when a custom condition is required,
// AND the variable isn't needed outside the if-statement
if (auto result = foo(); !result.has_value()) {
/* handle error */
}
// Bad: Using init-statement forces an 'else' block because 'result'
// goes out of scope, leading to nested/redundant code.
if (auto result = get_data(); !result.has_value()) {
return result.error();
} else {
process(result.value()); // Success path is forced into a nested block
}
// Good: Declare as a regular local variable to allow early exit
// and keep the success path un-nested (flat control flow).
auto result = get_data();
if (!result.has_value()) {
return result.error();
}
process(result
Install cpp-style in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the cpp-style skill do?
kotatsu C++ coding conventions — redundancy elimination (the rule we care most about), file organization, macro.h isolation, dual-mode exception policy, template deduction and type-trait rules, naming, modern C++ preferences. Read BEFORE writing or modifying any C++ code.
How do I install the cpp-style skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the cpp-style skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
by Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
by Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
by Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
by Anthropic