Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Latest commit

 

History

History
124 lines (103 loc) · 2.17 KB

STYLE.md

File metadata and controls

124 lines (103 loc) · 2.17 KB

This WIP document was made to cover the expected code-style for this repository. Please follow this style as closely as possible to make pull requests as simple as possible. Note that the examples below are mostly non-sensical and written for the sake of being examples.

Conditionals

When writing a conditional, be explicit with the expected result.

✔️ Do:

bool a = true;
if (a == true) {
    //
} else if (a == false) {
    //
}

❌ Don't:

bool a = true;
if (a) {
    //
} else if (!a) {
    //
}

Referencing Class Members

When writing code inside of a classes' method, refer to members using this..

✔️ Do:

class MyClass {
    public int a = 10;
    public int b = 10;

    public int Add() {
        return this.a + this.b;
    }
}

❌ Don't:

class MyClass {
    public int a = 10;
    public int b = 10;

    public int Add() {
        return a + b;
    }
}

Local Variables

When using local variables, prefix their names using an underscore. This does not need to be followed for variables used as iterators in loops.

✔️ Do:

string _myCharacterName = "John";
Console.WriteLine("My name is " + _myCharacterName);

❌ Don't:

string myCharacterName = "John";
Console.WriteLine("My name is " + myCharacterName);

Types

Avoid using var for types whenever possible. This does not need to be followed for one-off variables.

✔️ Do:

LInstance _instGlobal = _game.Instances[(double)LVariableScope.Global];
double _instX = _instGlobal.Variables["x"];
Console.WriteLine("Instance X position is: {0}", _instX);

❌ Don't:

var _instGlobal = _game.Instances[(double)LVariableScope.Global];
var _instX = _instGlobal.Variables["x"];
Console.WriteLine("Instance X position is: {0}", _instX);

Brackets

Brackets of all kinds should be put on the same line as the loop or conditional

✔️ Do:

int a = 0;
if (a > 0) {
    //
} else if (a  0) {

} else {

}

for(int i = 0; i < 100; i++) {
    //
}

❌ Don't:

int a = 0;
if (a > 0)
{
    //
}
else if (a < 0)
{
    //
}
else 
{
    //
}

for(int i = 0; i < 100; i++)
{
    //
}