Table of Contents

Language & Style Rules

All rules marked Error will block code review. Suggested rules are recommended but not enforced.

var Usage — Error

Always use var for local variables. The type is visible from the right-hand side.

// GOOD
var player = GetPlayer();
var count = 10;

// BAD
Player player = GetPlayer();
int count = 10;

Type Keywords over Framework Types — Error

// GOOD          // BAD
int count;       Int32 count;
string name;     String name;
bool active;     Boolean active;
float speed;     Single speed;

Never Use this. — Error

// GOOD          // BAD
_health = 100;   this._health = 100;
Initialize();    this.Initialize();

Pattern Matching over Cast/Null-Check — Error

// GOOD
if (obj is PlayerController player)
{
    player.Spawn();
}

// BAD — is-then-cast
if (obj is PlayerController)
{
    var player = (PlayerController)obj;
}

// BAD — as-then-null-check
var player = obj as PlayerController;
if (player != null) { }

Throw Expressions — Error

// GOOD
_name = name ?? throw new ArgumentNullException(nameof(name));

// BAD
if (name == null) throw new ArgumentNullException(nameof(name));
_name = name;

Performant Suggestions

Prefer performance over syntactic sugar. Avoid allocations in hot paths.

Pattern Use Avoid
Null coalescing cached ?? Compute() Ternary with null check
Null propagation name?.Length Manual null-then-access
string.Concat / interpolation Cold paths only Hot paths (use StringBuilder)
Object initializers new Config { X = 1 } Multi-line property sets
Collection initializers new List<int> { 1, 2 } Only for small, known-size lists
stackalloc / Span<T> Temp buffers in hot paths new byte[] allocations
in parameters Large structs (> 16 bytes) Small structs / reference types
readonly struct Value types that never mutate Mutable structs

Using Directives — Order

// System.* first, then alphabetical. No blank lines between groups.
using System;
using System.Collections.Generic;
using PixelEngine.Common;
using PixelEngine.Core.FSM;
using UnityEngine;

Performance-Critical References