Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

cpp-style

БесплатноБез исполняемых скриптовНе проверен

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

clice-ioот clice-io★ 37 звёзд на GitHub

Об этом скилле

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
Полный SKILL.md на GitHub

Установить cpp-style в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл cpp-style?

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.

Как установить скилл cpp-style?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл cpp-style запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить cpp-style с