Skip to content

Style guide

Lathreas edited this page Jun 16, 2021 · 6 revisions

This is a brief overview of the style we use for the code written here. Please set your code editor accordingly. Note that this is a work in progress and still subject to change.

When writing code, we use the following style:

  • We use tabs, not spaces, to indent code. The standard size of tabs should be 4 columns.
  • Line breaks are Linux-style, containing only the \LF.
  • The character limit for each line is 120 characters, unless the code is more readable when there is no wrap. This should be treated as exceptional cases, though. Comment blocks should never exceed 120 characters.

Commenting code

Within method definitions, please briefly describe what each section of the code is about to do conceptually. This should be done preferably with a comment on a single line, unless more explanation is needed. This divides the code in easily readable chunks that describe the code's purpose. The comment shouldn't re-state what is already written in code; instead it should help the reader understand the code. This is essential to understand unintuitive or math-heavy code.

// Calculate and return the interpolated value:
float a = -parameters[i]*dx + dy;
float t = (x-x1)/dx;

The comments should be written in the imperative form, so Do something: as opposed to This code does something:. These comments should end in a colon (:) to indicate that it describes the code after the comment. There should be a single space between the slashes // and the sentence.

Comment blocks that do not directly describe the code in the imperative form, but instead clarify some useful fact of a piece of unintuitive code do not need to end in a colon (:), but can instead end in a period (.).

Everything else

For all other conventions not described here, please refer to the C# standard style guide: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions

Clone this wiki locally