Naming Conventions¶
Goal: Consistent, readable, self-documenting code
Types¶
Classes¶
Convention: PascalCase
Interfaces¶
Convention: IPascalCase (I prefix)
Structs¶
Convention: PascalCase (same as classes)
Enums¶
Convention: PascalCase for enum, UPPER_SNAKE_CASE for values
Type Aliases¶
Convention: snake_case
Functions¶
Methods¶
Convention: snake_case
Free Functions¶
Convention: snake_case
Template Functions¶
Convention: snake_case
Variables¶
Member Variables¶
Convention: snake_case with trailing underscore
class MyClass {
private:
Sample sample_rate_;
BlockSize block_size_;
std::vector<Sample> buffer_;
};
Function Parameters¶
Convention: snake_case
void set_gain(float gain_db);
void process(const Sample* input, Sample* output, BlockSize num_samples);
Local Variables¶
Convention: snake_case
Constants¶
Convention: UPPER_SNAKE_CASE
Global Variables¶
Convention: g_snake_case (avoid globals!)
Files¶
Headers¶
Convention: snake_case.hpp
Source Files¶
Convention: snake_case.cpp
Interface Files¶
Convention: IPascalCase.hpp
Namespaces¶
Convention: snake_case
Macros (Avoid if Possible)¶
Convention: AUDIOLAB_UPPER_SNAKE_CASE
Examples¶
Good Names ✅¶
class BiquadFilter {
void set_cutoff_frequency(float frequency_hz);
float calculate_coefficient() const;
private:
float cutoff_frequency_;
float sample_rate_;
};
Bad Names ❌¶
class bqf { // Abbreviation unclear
void SetFreq(float f); // Inconsistent casing
float CalcCoef() const; // Abbreviation + mixed casing
private:
float freq; // No units, no trailing underscore
float sr; // Cryptic abbreviation
};
Special Cases¶
Acronyms¶
Treat as words:
Exception for well-known types:
Boolean Variables¶
Prefix with is/has/can:
Getters/Setters¶
Remember: Consistency matters more than the specific convention. Follow what's established.