Skip to content

Coding Standards

Gulvan edited this page May 3, 2023 · 4 revisions

WIP

Project structure

Packages

Assets

Layouts

Module Sub-Types

Formatting

General Examples

Class declaration

class SomeClass
{
   ...content...
}

Enum declaration

enum SomeEnum
{
    ConstructorA;
    ConstructorB(a:Int, b:String);
    
    ConstructorC; //When enum has lots of constructors, it is okay to split them into groups by leaving an empty line
    ConstructorD;
}

Class property

public var baz(default, null):Int;

Class method

public function foo(bar:T):S
{
   // Do something
}

Function modifier order

public/private static/override inline function

if

for

switch

Conditional compilation

Indentation

All code is 4-space indented

Line breaks

Block separators

In any case, subsequent paragraphs of code may be separated by at most one empty line.

Short form of switch

It is possible to omit the newline character after the colon in each case statement, but only if both conditions are met:

  1. switch is used as a value (for example, return switch or a = switch)

  2. Each body expression is simple enough

In this is the case, the constructs like this are allowed:

return switch this 
{
    case Resign: RESIGN_CONFIRMATION_MESSAGE;
    case Abort: ABORT_CONFIRMATION_MESSAGE;
    default: null;
}

Curly braces

Almost all of the code in this repository is written in Allman style (meaning: opening bracket is always placed on the new line).

The only exception is when the left curly brace follows the binary operator.

For example, this is the case for the anonymous functions:

var callback:Int->Void = s -> {
    // Do stuff...
};

...and wrapped anonymous objects being assigned to a variable:

var obj:Dynamic = {
    key1: value1,
    key2: value2,
    ...
};

Wrapping

Type hints

Variable hints

Function hints

Function types

Naming

Variables

Functions

Classes

Type Parameters

Packages