Skip to content

Code Style Document

Valk edited this page Sep 24, 2024 · 36 revisions

C# Coding Guidelines

General Guidelines

  • Avoid duplicate code.
  • Avoid over engineering code.
  • Classes / functions should have one responsibility.
  • Separation concerns. Divide the program into distinct sections, each addressing a separate concern.
  • Hide the internal state and functionality of an object and only allow access through a public set of functions
  • Try to make the code modular
  • Composition over Inheritance
  • Abstraction

Formatting

  • Indentation: 4 spaces.
  • Curly Braces: Always expand.
  • Using Directives: Above namespace.

Naming

  • PascalCase: Types, methods, properties, constants, events.
  • camelCase: Private fields, local variables, method args.
  • Prefixes: On for events, Set for set methods, Get for get methods

Language Features

  • Static Functions: Use when possible.
  • CallDeferred(): Avoid if alternatives exist.
  • var Keyword: Do not use ever.
  • C# Delegate Events: Always use over Godot signals.
  • Explicit Private Modifiers: Always specify private.

Commit Practices

  • Commit Separation: Separate large indentation changes.
Clone this wiki locally