Skip to main content

Overview

This project follows the standard C# language code conventions from Microsoft. This page provides a comprehensive summary of the conventions used throughout the codebase.

Naming Conventions

Code ElementConventionExample
ClassesTitleCaseclass Player
public FieldsTitleCasepublic float Speed;
private FieldslowerCaseprivate float targetFrameTime;
MethodsTitleCasepublic Update(), private GetMaxHeight()
Method parameterslowerCasewidth, height
ConstantslowerCaseconst int maxValue = 8;
EnumTitleCaseenum GameScreen
Enum membersTitleCaseScreenTitle
StructTitleCasestruct Material

Code Formatting

Operators

Always include spaces around operators:
OperatorConventionExample
Multiplicationvalue1 * value2int product = value * 6;
Divisionvalue1 / value2float division = value / 4.0f;
Additionvalue1 + value2int sum = value + 10;
Subtractionvalue1 - value2int res = value - 5;
Ternary(condition)? result1 : result2printf("Value is 0: %s", (value == 0)? "yes" : "no");

Float Values

Always use the f suffix with float literals:
float gravity = 10.0f;
float speed = 5.5f;

Indentation and Spacing

  • Four spaces are used, instead of TABS
  • Trailing spaces are always avoided
  • All defined Fields SHOULD BE ALWAYS initialized

Control Flow Statements

Control flow statements are followed by a space:

If Statements

if (condition) value = 0;

if ((value > 1) && (value < 50) && valueActive)
{
    // Code here
}
All conditions are always between parenthesis, but not boolean values.

While Loops

while (!WindowShouldClose())
{
    // Game loop
}

For Loops

for (int i = 0; i < NUM_VALUES; i++) printf("%i", i);

Switch Statements

switch (value)
{
    case 0:
    {
        // Code here
    } break;
    case 2: break;
    default: break;
}

Braces and Brackets

Braces and curly brackets always open-close in aligned mode:
void SomeFunction()
{
    // TODO: Do something here!
}
The opening brace is on a new line, aligned with the function declaration or control flow statement.

Best Practices

All defined fields should always be initialized when declared:
private float speed = 5.0f;
private int health = 100;
private bool isActive = false;
All conditions are always between parenthesis, but not boolean values:
if ((value > 1) && (value < 50) && valueActive)
{
    // valueActive is a boolean, so no parenthesis
}
Always include spaces around operators for readability:
// Good
int result = value1 + value2 * 3;

// Bad
int result=value1+value2*3;

Build docs developers (and LLMs) love