Coding Standards

1 minute read

C# Conventions

Naming

TypeConventionExample
Classes, Methods, PropertiesPascalCaseGameSessionService, LoadAsync()
Local variablescamelCaseuserName, isValid
Private fields_camelCase_configService, _isLoading
InterfacesIPrefixIConfigService
ConstantsPascalCaseMaxRetryCount

Code Style

// ✅ Correct
public async Task<Config> LoadAsync()
{
    if (condition)
    {
        await DoWorkAsync();
    }
}

// ❌ Wrong — K&R braces, missing Async suffix
public async Task<Config> Load() {
    if (condition) {
        await DoWork();
    }
}

TypeScript / React Conventions

Naming

TypeConventionExample
ComponentsPascalCase functionexport function TitleBar()
HookscamelCase, use-prefixuseGame(), useState()
FilesPascalCase for componentsTitleBar.tsx, Dashboard.tsx
Utility filescamelCaseipc.ts, helpers.ts
CSS variableskebab-case--bg-darkest, --accent
IPC channelskebab-colonhyprism:game:launch

Code Style

// ✅ Correct
export function MyComponent({ title }: { title: string }) {
  const [isOpen, setIsOpen] = useState(false);
  return <div className="flex items-center">{title}</div>;
}

// ❌ Wrong — default export, class component
export default class MyComponent extends React.Component {}

Anti-Patterns

// ❌ Referencing old Avalonia UI from services
using Avalonia.Controls;

// ❌ Using legacy localization files
var text = File.ReadAllText("assets/game-lang/en.lang");
// ❌ Direct Node.js / Electron API in renderer
const fs = require('fs');

// ❌ Hardcoded colors instead of theme tokens
<div style={{ color: '#7C5CFC' }}>  // Use var(--accent)

// ❌ Editing auto-generated ipc.ts manually