Skip to content
Ty Conner edited this page Mar 9, 2017 · 9 revisions

Code Style

To keep the code base clean and uniform this document should be referenced if you are planning to submit a pull request or work on the repository.

Windows line endings should be used at all times and files should all have an empty new line at the bottom.

Name Style

| Entity | Style | --- | --- | --- | Types and Namespaces | Pascal | Methods|Pascal Properties|Pascal Local variables|lowerCamel Parameters|lowerCamel Fields (public)|Pascal Fields (other)|lowerCamel Enumerations|Pascal Interfaces|IPascal (Pascal with I prefix, IFooInterface) Database Tables|snake_case Database Columns|lowerCamel

Braces and Brace Code Style

The overall global indent style is Allman with a few exceptions on where braces should be placed or added at all (redundant braces), see examples below.

class FooClass
{
    // empty simple methods with no body should have the braces on the same line with a single space separating them
    public virtual void SomeVirtualMethod() { }

    // properties with only a single function (or empty multiple functions) should be placed on a single line
    public uint FooProperty => 123u;
    public uint FooBarProperty { get { return 123u; } }
    public uint FooBarSetter { set { privateFoo = value; } }
    public uint EmptyProperty { get; set; }

    // properties should with multiple functions should still be single lined with the braces on seperate lines
    public uint SomeProperty
    {
        get { return 123u; }
        set { privateFoo = value; }
    }

    // simple one line methods should be placed on a single line
    public uint SimpleMethod() { return 123u; }

    public void StandardMethod()
    {
        Foo();
        DoSomethingElse();
        ThirdForGoodMeasure();
    }

    public void RedundantBraces()
    {
        // no braces required
        for (uint i = 0u; i < 5u; i++)
            DoSomething(i);

        foreach (var foo in bar)
            DoSomething(foo);

        // braces only required for the if block as it has multiple lines
        if (Foo())
        {
            FooBar();
            SecondFunction();
        }
        else
            return;

        // no braces required for either as both are single line
        if (Foo())
            FooBar();
        else
            FooBar2();

        // no braces required as additional lines fall under single line rule
        foreach (var foo in bar)
            if (foo.Bar())
                fooBar();
    }
}

Enumerations

The enumeration and it's value names should both be PascalCase, if specifying index values these much be spaced out to the match to length of the longest value name (see example), the final value in any enumeration should not have the ending comma.

Note: enumerations should be ordered by their values unless specified otherwise with a comment (opcode enumerations)

[Flags]
enum FooFlag
{
    None          = 0x00,
    Foo           = 0x01, // comment
    SomeOtherFlag = 0x02  // final value comment has an extra space due to missing comma
}

// ordered enumeration values do not need to indexed, this is up to your discretion
enum FooValues
{
    None,
    Foo,
    SomeOtherValue
}

enum FooValues
{
    None           = 0,
    Foo            = 1,
    SomeOtherValue = 2
}

Attributes

Attributes must be placed on a separate line to entity they are intended to effect, custom attributes must adhere to the standard class name style of PascalCase.

[FooAttribute]
class FooClass
{
    [FooAttribute]
    public uint FooValue { get; }

    [FooAttribute]
    public void FooMember() { }
}

enum FooEnum
{
    None,
    [FooAttribute]
    Foo
}

Database Updates

When making modifications to the database creating an update file is required, this should be placed in the respective update folder (auth/character/world) with the name format of YYYY_MM_DD_description.sql. A small description of the update should also be included in the respective updates.txt file.

2017_01_01_some_update.sql
2017_01_02_foo_update.sql