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 Element | Convention | Example |
|---|---|---|
| Classes | TitleCase | class Player |
public Fields | TitleCase | public float Speed; |
private Fields | lowerCase | private float targetFrameTime; |
| Methods | TitleCase | public Update(), private GetMaxHeight() |
| Method parameters | lowerCase | width, height |
| Constants | lowerCase | const int maxValue = 8; |
| Enum | TitleCase | enum GameScreen |
| Enum members | TitleCase | ScreenTitle |
| Struct | TitleCase | struct Material |
Code Formatting
Operators
Always include spaces around operators:| Operator | Convention | Example |
|---|---|---|
| Multiplication | value1 * value2 | int product = value * 6; |
| Division | value1 / value2 | float division = value / 4.0f; |
| Addition | value1 + value2 | int sum = value + 10; |
| Subtraction | value1 - value2 | int res = value - 5; |
| Ternary | (condition)? result1 : result2 | printf("Value is 0: %s", (value == 0)? "yes" : "no"); |
Float Values
Always use thef suffix with float literals:
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
All conditions are always between parenthesis, but not boolean values.
While Loops
For Loops
Switch Statements
Braces and Brackets
Braces and curly brackets always open-close in aligned mode:Best Practices
Field Initialization
Field Initialization
All defined fields should always be initialized when declared:
Condition Formatting
Condition Formatting
All conditions are always between parenthesis, but not boolean values:
Operator Spacing
Operator Spacing
Always include spaces around operators for readability: