Skip to content

Commit 4151378

Browse files
authored
Add notes on our coding style (#571)
* Add notes on our coding style Fixes #533 * Apply suggestions from code review
1 parent 09c0a79 commit 4151378

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,27 @@ The tool will replace the text with the following:
8989
```markdown
9090
See [§19.23.42](features.md#19-23-42-new-feature-added) for more details on how this feature affects everything. The [§19.23.42.1](features.md#19-23-42-1-general) clause has an overview.
9191
```
92+
93+
## Coding style
94+
95+
The code in the standard is optimized for reading the standard. In general, follow the existing code format. We've tried to be consistent throughout the standard.
96+
97+
We've adopted the following non-exhaustive rules:
98+
99+
- Use the latest C# syntax for the branch being edited. This is currently C# 7.3, except where older syntax is required for the example. Readers of the standard should see the latest syntax.
100+
- Use [Allman style braces](https://en.wikipedia.org/wiki/Indentation_style?msclkid=5bd8d8f5cd7b11ec82461327ced4546a#Allman_style) in most of our samples. The exception is when a method or type is empty, where the declaration, the opening and closing brace are on the same line.
101+
- Use a blank line between peer declarations. There are two exceptions to this rule:
102+
- If a group of peer declarations all have empty bodies (e.g. `class C {}` or `public void M() {}`, then no blank line is added between them.
103+
- Don't add a blank line where the concept is better illustrated without them. For example, multiple overloads of the same method may read better grouped without a blank line.
104+
- Elements of the same type can be grouped without blank lines. When that's done, there should be a blank line between elements of different types. (e.g. all private fields can be declared without a blank line, but there should be a blank line between the group of private fields and method declarations).
105+
- Indentation is 4 spaces. Use spaces, not tabs for the Word and PDF export formats.
106+
- Where a group of lines all have comments appended, the opening `//` should be on the same column on all lines.
107+
- Where expression bodied members are used, place all code on the same line if it fits. If it's too long, wrap after the `=>` token.
108+
- Line lengths cannot exceed 80 characters.
109+
- Use spaces around most tokens (e.g. `:` for base classes or interface implementation, `+` and all operators). Exceptions are:
110+
- `<` and `>` to declare generic types and methods
111+
- `(` and `)`. No spaces around parentheses on method declarations.
112+
- No space after the opening `(` and no space preceding the closing `)` for other expressions.
113+
- No spaces on `[]` for array declarations.
114+
115+
ANTLR Grammar productions should not exceed 80 characters.

0 commit comments

Comments
 (0)