Skip to content

Styling Guide

Zenvin edited this page Dec 10, 2021 · 8 revisions

Git

  • Commit messages using imperative present tense with first letter capitalized, that is e.g. Add running, Change inventory system
  • Branches use lower-kebab-case and are written as nouns, that is e.g. task/boss-balance, task/inventory-addition

Unity

  • Use empty objects prefixed with --- to create headers
  • Use spaces in names and use capital letter like Player and End Level Trigger
  • Avoid types in asset names

C#

Names

  • PascalCase for everything but:
  • camelCase for private variables, local variables and parameters
  • _camelCaseWithUnderscore for backing fields
  • Nouns for types
    • Single-word type names should preferably be used for POCOs
    • Suffixes like -Controller or -Manager can be used as fitting
    • Arbitrary names (e.g. UserInterface) are to be avoided
    • Abbreviations may be used for common terms (e.g. "User Interface" ➜ "UI")
  • Verbs for methods
  • Adjectives for interfaces
  • Use those prefixes:
    • I... - Interfaces
    • Try... - Methods with out parameters that return bool
    • Co_ - Coroutines
  • Use those suffixes:
    • ...Async - Async methods returning Task

Keywords and Attributes

  • Use explicit private
  • You can use var when that makes the code nicer without hindering readability
  • Inline attribute in case only one is present, place the attribute above the member otherwise

Namespaces

  • Always place the code within a namespace, do not leave anything in global scope
  • Use using over using namespaces in code, that is avoid System.Collections.Generic.List and similar in code
  • Remove unused using statements

Indentation rules

  • Indent by 4 spaces
  • Put the bracket on a new line
  • If you use one line if statements, break the line after the condition

Code style

  • Prefer if statements with { } unless it hinders readability
  • Guard clauses should not use { }
  • Put a space between keywords and arguments like so: if (condition)
  • Do not use regions
  • Do use lambdas and expression body properties when it makes sense
  • Do not use expression body methods

Member order

Enums and Lists

  • Last element of a list or enum should also be followed with ,
  • Use PascalCase for enum options
  • Flags should have explicit values introduced via shift operator like so SomeEnumOption = 1 << 5

Clone this wiki locally