Skip to content

Latest commit

 

History

History
223 lines (160 loc) · 6.75 KB

todo_code-style.md

File metadata and controls

223 lines (160 loc) · 6.75 KB
domain product-code
type reference
status todo
owner <!-- team/role that owns code conventions -->
last_reviewed

TODO — Code Style Guide

This document defines the code style and formatting conventions for this project. Consistency matters more than any individual rule, when in doubt, follow existing patterns in the codebase.


Tooling

# Check for style errors
# Auto-fix formatting

All checks must pass before a PR can be merged. The CI pipeline enforces this automatically, see operations/concept/ci-cd-pipeline.


General Principles

  • Clarity over cleverness : write code for the next reader, not only the compiler
  • Explicit over implicit : avoid magic; name things for what they do
  • Small functions : each function should do one thing
  • No dead code : remove commented-out code before committing

Naming Conventions

Go

Element Convention Example
Files snake_case http_server.go
Packages short, lowercase, no underscores httputil
Exported identifiers PascalCase UserService
Unexported identifiers camelCase getUserByID
Constants PascalCase or camelCase, grouped in a const block MaxRetryCount

Rust

Element Convention Example
Files / modules snake_case user_service.rs
Types, traits, enums PascalCase UserService
Functions, variables snake_case get_user_by_id
Constants, statics SCREAMING_SNAKE_CASE MAX_RETRY_COUNT
Macros snake_case! vec!

C

Element Convention Example
Files snake_case user_service.c
Functions snake_case get_user_by_id
Types (structs, typedefs) snake_case with _t suffix user_t
Constants, macros SCREAMING_SNAKE_CASE MAX_RETRY_COUNT
Global variables snake_case, g_ prefix optional g_active_count

C++

Element Convention Example
Files snake_case user_service.cpp
Classes, structs PascalCase UserService
Methods, functions camelCase getUserById
Member variables camelCase_ (trailing underscore) retryCount_
Constants kPascalCase kMaxRetryCount

TypeScript / JavaScript

Element Convention Example
Files kebab-case user-service.ts
Classes PascalCase UserService
Functions, methods camelCase getUserById
Constants UPPER_SNAKE_CASE MAX_RETRY_COUNT
Private members #prefixed or _prefixed #cache

OCaml

Element Convention Example
Files snake_case user_service.ml
Modules PascalCase UserService
Values, functions snake_case get_user_by_id
Constructors, variants PascalCase UserNotFound
Type names snake_case user_id

Python

Element Convention Example
Files / modules snake_case user_service.py
Classes PascalCase UserService
Functions, variables snake_case get_user_by_id
Constants UPPER_SNAKE_CASE MAX_RETRY_COUNT
"Private" members _prefixed _cache

Java

Element Convention Example
Files PascalCase, matching the public class name UserService.java
Classes, interfaces PascalCase UserService
Methods, variables camelCase getUserById
Constants UPPER_SNAKE_CASE (static final) MAX_RETRY_COUNT
Packages all-lowercase, dot-separated com.example.userservice

C#

Element Convention Example
Files PascalCase, matching the class name UserService.cs
Classes, methods, properties PascalCase GetUserById
Local variables, parameters camelCase retryCount
Constants PascalCase MaxRetryCount
Private fields _camelCase _cache

Formatting

  • Indentation: X spaces (no tabs)
  • Max line length: 100 characters
  • Trailing commas: yes / no
  • Quotes: single / double

Import / Dependency Order

  1. Standard library / built-ins
  2. Third-party packages
  3. Internal packages / modules
  4. Relative imports

Separate each group with a blank line.


Error Handling

  • Never swallow errors silently, log or propagate
  • Use typed/structured errors where the language supports it
  • Validate inputs at system boundaries; trust internal code

Testing Conventions

  • Tests live next to the code they test, or in a dedicated tests/ directory
  • Each test should be independent and not rely on shared mutable state
  • Test names should describe the expected behavior: should return 404 when user not found

Running the Full Validation Suite

# Replace with your actual commands
# Lint
# Type-check (if applicable)
# Tests
# Build

All four must pass before pushing.

See also