Skip to content

Code Standards

BeltranDaniel edited this page Aug 16, 2021 · 13 revisions

Code Standards

This document is the C# coding standard that will be applied to develop AEDRA project.

Indentation

One tab (4 spaces)

Naming conventions

Object Name Notation Plural Abbreviation Underscores Example
Namespace name PascalCase Yes No No using System;
Files and folders PascalCase Yes No No MenuIcon.png
Class name PascalCase No No No Node
Constructor name PascalCase No No No Node()
Method name PascalCase Yes No No AddNode()
Method arguments camelCase Yes Yes No AddNode(int num)
Local variables camelCase Yes Yes No int num;
Constants name PascalCase No No No int NodeRadius;
Field name camelCase Yes Yes Yes Node _leftChild;
Public members PascalCase Yes Yes No [SerializeField] public int Num;
Properties name PascalCase Yes Yes No int Num {get; set;}
Delegate name PascalCase No Yes No delegate int Function();
Enum type name PascalCase Yes No No enum TreeType

Notes:

  • Namespace is package equivalent
  • A Field is a private attribute without getters and setters
  • A Property is an attribute with getters and setters

Braces placement

The opening brace ( { ) should be placed at the end of the line immediately preceding the block of code it contains. Example: 

Braces placement

public void function()
{

}

Conditional braces placement

if ( condition ) {
   return true;
} else {
   return false;
}

Wrapping lines

When doing line breaks separate by comma or by points accordingly, the new lines should be aligned 1 tab space to the right.

Line break (Points)

myMethodInvocation( myParemeter, mySecondParameter)
   .findBy( myValue )
   .sort();

Line break (Commas)

myClassConstructor( thisIsAlongParameter, thisIsAlongParameter,
   thisIsAlongParameter, thisIsAlongParameter);

Commas:

After each comma, there should be a blank space. Example: myFunction(int a, string b, int c)

Comments:

Follow this standard: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments

  • Methods: Minimum required comments for each method are Description, parameters and return. Do not comment getters, setters and default constructors.
  • Classes: For classes document a brief description of the class purpose.
  • Inside code methods: Comment complex and multi-step methods, with brief one-line comments. Try to avoid block comments inside the code.

Coding practices to avoid:

  • Avoid using Thread.sleep.
  • Avoid using break statements in while loops.
  • Avoid using the “continue” keyword.
  • Avoid using if, while, etc without braces when there are one line blocks.

Clone this wiki locally