Naming Conventions
Part of the Fundamentals section of Coddy's Rust journey — lesson 11 of 75.
In Rust, there are several naming conventions that you should follow to make your code more readable and maintainable. They are widely accepted by the Rust community.
Here are some common naming conventions:
- Variables should be named using
snake_case, which means all lowercase letters with underscores between words. For example:my_variable,calculate_total.
- Avoid overly short or cryptic names. Choose descriptive names that clearly indicate the purpose of the variable.
- Names can contain letters, digits and underscores.
- Names must start with a letter or an underscore
_.
- Basic counters usually use single letter such as
i,j, though it's worth noting that more descriptive names might be better when the context is more complex.
Cheat sheet
Rust naming conventions for variables:
- Use
snake_case- all lowercase with underscores between words - Choose descriptive names that indicate the variable's purpose
- Names can contain letters, digits, and underscores
- Names must start with a letter or underscore
_ - Basic counters can use single letters like
i,j
Examples: my_variable, calculate_total
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsString Comparison5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 33Variables Part 2
Type DeclarationNaming ConventionsType InferenceRecap - Initialize VariablesType Casting9Loops
For Over SeriesWhile LoopBreakContinueNested LoopLoop LabelsInfinite LoopRecap - Dynamic Input