Code Formatting
Format settings for Visual Studio
This document explains the Metamation conventions for formatting C# code.
Tabs
Use Spaces instead of Tab characters in source files. Set the indent level as 3 spaces. (2 is too narrow, 4 is too wide, 3 is the Goldilocks number).
Indentation, Newlines and Spacing
Metamation indentation style is a mix between the K&R Style and the 1TBS (One True Brace Style). Like K&R style, we generally dispense with the braces when there is only one statement in the block. Like 1TBS, we place the braces opening a function on the same line as the function header.
That is:
void CheckLevel () {
if (nLevel > 0 && !mLevelStack.IsEmpty)
PopLevel ();
}
However, this is discretionary. If you think adding braces clarifies the meaning, add them.
Here are how we configure Visual Studio to get the exact indentation, newlines and spacing settings that we want. Once configured, the editor will reformat your code using these settings each time you complete a block, ensuring consistency. Go to the Tools / Options dialog, and you can find these settings under Text Editor / C# / Code Style / Formatting
A key point with these brace styles it that we try to reduce the number of lines code occupies. Thus, the New Lines section of the Visual Studio editor is configured by turning all the new line check-boxes off:
Continuing the brevity theme, the Wrapping settings are configured thus:
The spacing rules are set like this: