-
Notifications
You must be signed in to change notification settings - Fork 3
Style
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 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();
};
}
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(); };
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();
};
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
.
- Home
- Introduction
- Motivation
- Features
- Tutorial
- Library
- FAQ
- General
- Interoperability
- Syntax
- Type System
- Macros and CTE
- Specification
- Introduction
- Lexical
- Common Grammar Elements
- Modules and Bundles
- Type System
- Declarations
- Expressions
- Macros
- Compile-Time Evaluation
- Memory Management
- Application Binary Interface
- Foreign Function Interface
- Unit Testing
- Documentation Comments
- Style
- Indentation
- Braces
- Spacing
- Naming