Naming conventions

This chapter covers standard naming conventions.

1. Casing

In general, use PascalCase for names of types or traits and use snake_case otherwise. More precisely:

Item Convention

Modules

snake_case

Types

PascalCase

Traits

PascalCase

Enum variants

PascalCase

Struct fields

snake_case

Functions

snake_case

Methods

snake_case

Variables

snake_case

Constants

UPPER_CASE

Type parameters

PascalCase generally, a single letter like T usually

In PascalCase, acronyms count as one word: use Sha rather than SHA. In snake_case, acronyms are lower-cased: sha3_hash.

In snake_case or UPPER_CASE, a word should never consist of a single character unless it is a digit or the last word. So, we have btree_map rather than b_tree_map, but PI_2 rather than PI2.

Language implementations can emit warnings when names do not follow these rules.

2. Underscore prefix (e.g. _foo)

The name of an unused variable must start with an _ (a common example is simply "_").

let _unused = compute_something();

Language implementations can emit warnings when a variable not starting with an underscore is only written-to but is never read. The same applies when a variable starting with an underscore is read.