Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

cpp-style

FreeNo executable scriptsNot checked

kotatsu C++ coding conventions — redundancy elimination (the rule we care most about), file organization, macro.h isolation, dual-mode exception policy…

clice-ioby clice-io★ 37 GitHub stars

About 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, else after return, 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 .h with #pragma once — never include guards. Public headers live under include/kotatsu/<module>/.
  • Source extensions are mixed across modules (.cpp in some, .cc in 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 a macro.h contains zero #include directives — 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_THROW and the platform feature macros in kotatsu/support/config.h — stay where they are.

Data & Types

  • struct by default, even for types with methods. class only when there is a real invariant that private access protects.
  • enum class with 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&, never T const&.

Errors, Exceptions & Defense

  • kotatsu is a library that builds both with and without exceptions (KOTATSU_ENABLE_EXCEPTIONS). Library code never writes bare throw/try/catch — use the KOTATSU_THROW / KOTATSU_TRY / KOTATSU_CATCH_ALL / KOTATSU_RETHROW macros from kotatsu/support/config.h, which degrade to std::abort() in the no-exceptions build.
  • Fallible synchronous operations return std::expected<T, E>; async code uses kotatsu's outcome types.
  • assert pins preconditions; impossible branches end in std::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 if with 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 bool or evaluates implicitly (e.g., standard error codes, custom error wrappers), omit the redundant condition check.
  • Avoid forced else branches: If scoping the variable inside the if requires you to introduce an else block 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
Full SKILL.md on GitHub

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
Sign up freeI already have an account

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

Compare cpp-style with