Skip to main content

Overview

Dolphin uses clang-format 19.1 to enforce consistent code formatting across the entire codebase. This guide details the specific coding standards and formatting rules.
In case of conflicts between this guide and clang-format rules, follow clang-format.

Setting Up clang-format

Automated Formatting

Format all staged files before committing:

Line Endings

Windows users must configure git to checkout UNIX-style line endings:

General Formatting Rules

Line Length and Indentation

  • Maximum line length: 100 characters
  • Indentation: 2 spaces per level (no tabs)
  • Tab width: 2 spaces
Try to keep lines under 80-90 characters when possible for better readability.

Brace Placement

Opening braces go on the next line for:
  • Namespaces
  • Classes
  • Functions
  • Enums, structs, unions
  • Conditionals and loops

Pointers and References

Place the * or & against the type name, not the variable name:

Comments

Use single-line comments (//), not multi-line comments (/* */):

Conditionals and Loops

Don’t collapse single-line bodies onto the same line as the header:

Naming Conventions

Classes, Enums, Functions, Structs

Use UpperCamelCase. Uppercase abbreviations:

Constants

Fully uppercase with underscores:

Variables

Lowercase with underscores:

Variable Prefixes

Do not use Hungarian notation except for these specific prefixes:

Conditional Statements

Don’t leave else or else if dangling unless the if lacks braces:

Classes and Structs

When to Use Each

Class Layout

Order sections as: public, protected, private Within each section, order as:
  1. Constructor
  2. Destructor
  3. Operator overloads
  4. Functions
  5. Variables (static before non-static)

Final and Override Specifiers

Mark classes/functions that shouldn’t be inherited/overridden with final:
Mark overridden functions with override:

Code-Specific Guidelines

Modern C++ Practices

1

Use nullptr

Use nullptr instead of the NULL macro:
2

Prefer range-based for loops

Use range-based for loops over iterators when possible:
3

Avoid raw pointers

Prefer STL containers and smart pointers:
Raw pointers are acceptable when interfacing with C libraries or when unavoidable.
4

Limit auto usage

Only use auto when the type is obvious:

Header Files

1

Use #pragma once

This project uses #pragma once as header guards.
2

Include order

Order includes in source files as:
  1. The header for this source file
  2. Standard library headers (alphabetically)
  3. System-specific headers (in #ifdef blocks)
  4. Other Dolphin headers (alphabetically)
3

Relative paths

Include project headers relative to [Dolphin Root]/Source/Core:
4

Remove unused includes

Remove unnecessary or duplicate includes.

Loops

Functions

Const-correctness for parameters:
Pointer parameters for modification: Make modification syntactically obvious by using pointers:

Miscellaneous

  • Avoid goto unless you have a really good reason
  • Fix compiler warnings when found
  • Don’t use using namespace [x]; in headers (avoid it elsewhere too)
  • Use prefix increment in for-loops: ++var instead of var++

clang-format Configuration

The project’s .clang-format file (located at Source/.clang-format) defines:
View the complete configuration at Source/.clang-format in the repository.

Android Code Style

Kotlin

Use the built-in official Kotlin code style in Android Studio.

Java

Import the Dolphin Java code style:
1

Open Code Style settings

Navigate to Settings → Code Style in Android Studio.
2

Import scheme

Click the gear icon, select Import Scheme, and choose dolphin/Source/Android/code-style-java.xml.
3

Format code

Select code and press Ctrl+Alt+L to automatically format it.

Next Steps

Testing

Learn about testing practices and frameworks

Debugging

Explore debugging tools and techniques