Skip to content

Naming Conventions

Goal: Consistent, readable, self-documenting code

Types

Classes

Convention: PascalCase

class AudioProcessor { };
class BiquadFilter { };
class FFTProcessor { };

Interfaces

Convention: IPascalCase (I prefix)

class IAudioProcessor { };
class IParameter { };
class IEventListener { };

Structs

Convention: PascalCase (same as classes)

struct BufferConfig { };
struct ProcessingContext { };

Enums

Convention: PascalCase for enum, UPPER_SNAKE_CASE for values

enum class ProcessorState {
    UNINITIALIZED,
    PREPARED,
    ACTIVE
};

Type Aliases

Convention: snake_case

using sample_rate = uint32_t;
using channel_count = uint8_t;

Functions

Methods

Convention: snake_case

void prepare();
void set_sample_rate(SampleRate rate);
Sample get_sample(SampleIndex index) const;

Free Functions

Convention: snake_case

float calculate_gain(float db);
void process_buffer(Sample* buffer, BlockSize size);

Template Functions

Convention: snake_case

template<typename T>
T clamp(T value, T min, T max);

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

void foo() {
    int sample_count = 0;
    float gain_linear = 1.0f;
}

Constants

Convention: UPPER_SNAKE_CASE

constexpr int MAX_CHANNELS = 32;
constexpr float PI = 3.14159f;

Global Variables

Convention: g_snake_case (avoid globals!)

// Avoid, but if necessary:
static float g_global_sample_rate = 44100.0f;

Files

Headers

Convention: snake_case.hpp

audio_processor.hpp
buffer_types.hpp
parameter_system.hpp

Source Files

Convention: snake_case.cpp

audio_processor.cpp
buffer_types.cpp
parameter_system.cpp

Interface Files

Convention: IPascalCase.hpp

IAudioProcessor.hpp
IParameter.hpp
IEventListener.hpp

Namespaces

Convention: snake_case

namespace audiolab {
namespace dsp {
namespace filters {
    // ...
}
}
}

Macros (Avoid if Possible)

Convention: AUDIOLAB_UPPER_SNAKE_CASE

#define AUDIOLAB_VERSION_MAJOR 1
#define AUDIOLAB_API __declspec(dllexport)

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:

class FftProcessor { };   // Not FFTProcessor
class MidiHandler { };    // Not MIDIHandler

Exception for well-known types:

using SampleID = uint32_t;  // ID is common enough

Boolean Variables

Prefix with is/has/can:

bool is_active_;
bool has_input_;
bool can_process_;

Getters/Setters

Sample get_sample() const;
void set_sample(Sample value);

Remember: Consistency matters more than the specific convention. Follow what's established.