Skip to content

Coding Conventions

André edited this page Mar 21, 2022 · 28 revisions

The coding convention helps create a consistent look for the code. Readers will understand the code more quickly and it facilitates copying, changing and maintaining the code.

Naming Conventions

In this project, we use several naming conventions.

Be aware that protected elements are treated the same way as public elements

Pascal Case

Always use pascal casing ("PascalCasing") when naming classes, structs, properties and methods.

public class MyClass { }

public struct MyStruct { }

public int MyInteger { get; set; }

private void MyMethod() { }

Camel Case

Always use camel casing ("camelCasing") when naming private fields and method parameters.

public class MyClass
{
    private bool myBoolean;

    public void MyMethod(int myParameter) { }
}

Layout Conventions

A good layout uses formatting to emphasize the structure of your code and makes the code easier to read.

  • Use four-character indents and save TABs as spaces.
public struct MyStruct
{
----private int myInteger;
}
  • Write only one statement per line.
  • Write only one declaration per line.
  • Continuation lines should be indented one time only.
var myObject = new MyClass(0,
    40.0f,
    "text");
  • Use parentheses to make clauses in an expression apparent, as shown in the following code:
if((value1 > value2) && (value1 > value3))
{
    // Block of code to execute if the condition is true
}

Clone this wiki locally