Conventions
Project structure, naming, and code style conventions
Project Structure
- Source files are snake_case with the
.nkextension - The entry point for binary projects must be called
main.nk - The
main.nkfile should be in- Project root for single-entry point projects
- In
main/<name>/for multiple binaries
- Internal source code should go in the
src/directory - Exported source code should go in the
exp/directory - A project must have a
nook.tomlfile in the root
Naming Conventions
- Struct, interface, and type alias names should be PascalCase
- Variable and function names should be snake_case
- Constant names should be SCREAMING_SNAKE_CASE
- Identifiers should be concise but descriptive
- Acronyms are treated like words, so
HttpServerinstead ofHTTPServer - Avoid leading or trailing underscores
Code Style
- Max one line of whitespace separating lines
- Source files should group content in this order:
- Imports
- Stdlib > 3rd party > internal
- Global constant definitions
- Global variable definitions
- Struct definitions
- Structs required by others defined first
- Dynamic function definitions
- Static function definitions
- Imports
- Lines of code should be grouped by whitespace into small regions when possible
- Opening braces -
{- should have a space:- Preceding when followed by a new line
- Following when followed by a token on the same line
- Unary operators should not have whitespace between operator and operand
- Binary operators should have whitespace between operator and operands, except:
- Multiplication, division, exponentiation
- All functions should have a brief descriptive comment above the signature
- Struct definitions should include a brief descriptive comment below the name
Data Types ➡️