Compiler style guide
Note
This style guide is only for the developers of the compiler and other official projects. For the I-Language style guide see ILEP 008.
All code
Comments
Comments should always be written in the third person when describing an action, e.g. # Removes the old files instead of # Remove the old files.
Rust code
Generally just refer to the official rust style guide. There are some exceptions you should follow though.
Code groups
Groups start with a three line header like this:
Where the top and bottom lines are as long as the middle one. The title should be in SCREAMING_SNAKE_CASE.
There should always be two blank lines above, but not below a group header.
The groups should be in the following order
- Header with copyright notice (without a header)
- Global attributes (
#![...]) - Imports
- Constants
- Statics
typestatements- Trait definitions
- Type definitions with trait implementations in this order (without own headers)
- Implementation without a trait
- Trait implementations with traits from the same library
- Trait implementations with traits from libraries in the same project
- Trait implementations with traits from the standard library
- Trait implementations with traits from other dependencies
- Helper functions
- The
mainfunction/the most important function (e.g. thelexfunction in the lexer, theparsefunction in the parser, etc.)
Dependencies
Always prefer core over std.
Try to use functionality from the standard library instead of adding new dependencies if it doesn't add to much complexity.
Mutable statics
Use mutable statics only when it's the only reasonable option available.
Mutable statics' names should be in SCREAMING_SNAKE_CASE, even though they behave more like variables to make other people irritated.
Sorting imports
Sort imports in the following order
coreandstdimportsself,superandcrateimports- Imports from other crates in the same project
- Imports from other libraries
- Conditional imports (
#[cfg(...)])
There should be one blank line in between import groups. For sorting imports within groups, refer to the official style guide.