Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
alexrp edited this page Mar 25, 2013 · 6 revisions

This is the Flect code style guide. It is advised that Flect code stick to these conventions (especially the naming conventions) in order to maintain consistency across Flect source bases.

Indentation

Indentation is done with 4 space characters per level. Avoid using hard tabs.

Good:

pub fn foo() -> unit {
    bar();

    if baz() {
        qux();
    };
}

Bad:

pub fn foo() -> unit {
  bar();

  if baz() {
    qux();
  };
}

Braces

Opening braces should be placed immediately after the declaration or expression they associate with. Closing braces should be on a separate line except when associated with the continuation of an expression (such as an else clause) or when a declaration or expression is entirely on a single line.

Good:

pub fn foo() -> unit {
    ();
}

Good:

pub struct Foo {
    pub x : int;
}

Good:

pub union Foo {
    Bar { pub x : uint; }
    Foo {
        pub x : int;
        pub y : uint;
    }
}

Good:

if foo() {
    bar();
} else {
    baz();
};

Good:

let x = if foo() { bar(); } else { baz(); };

Bad:

pub struct Foo
{
}

Bad:

if foo()
{
    baz();
};

Bad:

if foo() {
    baz();
}
else { baz(); };

Spacing

A space should always be placed between the left-hand side, operator, and right-hand side in binary expressions. The same rule applies to braces; always have space between an opening/closing brace and the declaration, expression, or clause it associates with.

A space should not be inserted between a function name and its argument list; however, a space should always be inserted after a comma in an argument list (if not broken across multiple lines).

Good:

let x = y + z;

Good:

foo(bar(), baz());

Good:

foo(bar(),
    baz());

Good:

if foo() {
    bar();
};

Bad:

let x = y+z;

Bad:

foo (bar(), baz ());

Bad:

if foo(){
    bar();
};

Naming

The following simple rules are used for naming:

  • Module names are snake_case.
  • Function and macro names are snake_case.
  • Variable names (globals, locals, and parameters alike) are snake_case.
  • Structure, union, and enumeration names are PascalCase.
  • Newtype names are mostly PascalCase (snake_case is OK in some special cases).
  • Trait names are PascalCase.
  • Preprocessor directive names are Upper_Snake_Case.
Clone this wiki locally