-
Notifications
You must be signed in to change notification settings - Fork 22
Coding Standard
We have StyleCop in this project, so a significant amount of coding standard documentation does not need to be written as it will warn you if you do anything different to what it wants. For the most part you should follow the standard C# development practices (ex: Allman style, upper case functions and non-private variables, etc).
The following are some things to keep in mind while making your code:
-
Nullable references is turned on (as we're on C# 8 at the time of writing). This means you cannot declare a field and set it to
null
without it having a question mark next to it (unless you set it in the constructor):
public class MyClass
{
public MyObject? Object;
}
This helps us avoid null reference exceptions completely. You can also condense code with the null-coalescing operator or invoking things like Object?.Member
in the case of it being null.
- You can convert one liners into the arrow notation. This means if you have
public bool Something()
{
return something + anotherThing < 5;
}
you can do:
public bool Something() => something + anotherThing < 5;
- Local functions are okay to use, especially in performant areas over lambdas.
This has been great in the physics code, feel free to use it wherever. I don't think we'd want a nested local function inside of a local function, but it'd have to be evaluated on a case-by-case basis.
- Check Util/Extensions/ for any extension types. Extensions are very awesome, you should try those out or add any if a [standard] library class is missing anything.