These conventions apply to all C and C++ code across Compute Flow, including public APIs, core implementation, runners, bindings, bricks, command-line tools, tests, and examples.
Naming
- Classes and structs use PascalCase, for example
Qwen3TTS. - Functions use snake_case.
- Variables use lower snake_case with no capital letters, for example
qwen_tts_. - Counting variables use
num_<name>instead ofn_<name>. - Constants use the
k_prefix and should beconstexprwhenever possible. - Private class members use a leading underscore:
_<name>.
Types
- Use fixed-width integer types from
cstdintto make intent explicit. - Examples:
int32_t,int64_t. - Do not qualify fixed-width integer types with
std::; useuint32_tinstead ofstd::uint32_t. - Use
int32_tinstead ofint. - Prefer
int64_toruint64_tinstead ofsize_twhenever possible. - Use
floatinstead offloat32. - Do not use
float16to keep compatibility across supported operating systems.
Const And Immutability
- If a variable is declared and never changed, declare it
const. - Prefer
constexprfor compile-time constants. - At interfaces, primitive parameters should not be
const. Pass them by value. - Pass classes or structs by reference, and use
constreferences for inputs.
Functions And Namespaces
- File-local
staticfunctions should live in an anonymous namespace. - Keep variable definitions close to their first use.
- Add an empty line after a completed group of variable definitions before subsequent checks, function calls, or control flow.
- Add an empty line before and after a standalone function call. Calls that form one logical block may remain together.
Control Flow
- Always use braces for control-flow bodies, even when the body contains only one statement.
Casting
- Use
static_castfor basic primitive conversions instead of C-style casts.
Includes
- Include only the headers you need.
Examples
namespace {
int32_t count_tokens(const std::vector<int32_t>& token_ids) {
const int32_t num_tokens = static_cast<int32_t>(token_ids.size());
return num_tokens;
}
} // namespace
class MyClass {
public:
explicit MyClass(const Config& config);
private:
static constexpr int32_t k_max_tokens = 8192;
int32_t _num_speakers = 0;
};