LM Applications Team Style Guide

Nicholas Benson edited this page Jun 16, 2017 · 1 revision

Variable & Property Naming

public    lowerCamelCase;
protected _lowerCamelCase;
private   _lowerCamelCase;
private constant ALL_CAPS_WITH_UNDERLINES
public    lowerCamelCase { get; set; }
protected _lowerCamelCase { get; set; }
private   _lowerCamelCase { get; set; }

Lazy-loaded property pattern

// If a lazily-loaded property is itself private, use an alternative name
// for the backing variable to clarify that the property should be used under
// normal circumstances instead of the backing variable.
private Foo _backingMyPrivateLazilyLoadedVariable;
private Foo _myPrivateLazyLoadedVariable {
  get {
    if (_backingMyPrivateLazilyLoadedVariable == null) {
      _backingMyPrivateLazilyLoadedVariable = new Foo();
    }
    return _backingMyPrivateLazilyLoadedVariable;
  }
}

Method Naming

public     UpperCamelCase();
protected  lowerCamelCase();
private    lowerCamelCase();

Braces

if (condition) {
} else { // else can optionally be on its own line.
}
do {
} while (condition);
for (int i = 0; i < count; i++) {
}
switch (num) {
  case 0:
    break;
  case 1:
    break;
}
public void Foo() {
}
public class Bar {
}

Spaces and Parentheses

public void Method(int arg1, int arg2) {
}
if (condition) {
}
for (int i = 0; i < count; i++) {
}
callDisMethod(args, args, args);

Indenting

Spaces per tab: 2

Tabs or spaces: Spaces

Starting a new namespace should always indent.

Unity Inspector Fields

Inspector fields are allowed to be public, but don't need to be.

Favor using [Tooltip] to improve discoverability and documentation. Favor using [Header] to organize fields by category when relevant. Favor using [SerializeFIeld] explicitly -- that is, even on public inspector fields.

Enums

enum UpperCamelCase {
  EnumValue0,
  EnumValue1,
}

If the integer value of an enum is important, the value must always be specified in the enum itself. If the value or relationship between values is not important, they can be omitted.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.