TeachMate
My ProgressJoin Session

Advanced Topics

0/9 completed · ~0h 36m

All Topics
C++LearnAdvanced Topics
1 / 9

Naming Conventions

intermediate
2 min read

Consistent naming makes code readable and maintainable.

C++ Naming Conventions

PascalCase: StudentBankAccount, calculateArea

Use for: classes, structs, enums, functions, namespaces

camelCase: studentCount, calculateTotal

Use for: variables, functions, parameters

UPPER_SNAKE_CASE: MAX_SIZE, PI, DEFAULT_TIMEOUT

Use for: constants, macros

snake_case: student_bank_account, calculate_area

Use for: variables, functions (alternative style)

Hungarian Notation: iCount, szName, pPointer

Avoid: redundant with types, hard to read

Examples

class StudentManager {           // PascalCase
    int studentCount;             // camelCase
    const int MAX_STUDENTS = 30;  // UPPER_SNAKE_CASE

    void calculateAverage() {     // camelCase
        double total = 0;          // camelCase
        for (int i = 0; i < studentCount; i++) {  // camelCase
            total += students[i].gpa;
        }
    }
};

Naming Tips

  • Be descriptive: studentCount (not sc)
  • Use nouns for variables: student, score, index
  • Use verbs for functions: calculate, print, validate
  • Avoid abbreviations: count (not cnt)
  • Be consistent across your project

File Naming

  • PascalCase for classes: StudentManager.cpp
  • snake_case for utilities: string_utils.cpp
  • Match header and source files

Key takeaway: Use PascalCase for types, camelCase for variables, and UPPER_SNAKE_CASE for constants — consistency matters most.

Try it: Rename a small class and its variables to follow PascalCase for types, camelCase for variables, and UPPER_SNAKE_CASE for constants.

TeachMate - Interactive learning platform for bachelor students

HomeLearnJoin Session|2 Subjects