coding-guidelines icon indicating copy to clipboard operation
coding-guidelines copied to clipboard

Add variable naming section on expressing unit of the type

Open faern opened this issue 4 years ago • 0 comments

If a type does not include the unit of the value, the variable name has to. Otherwise it becomes hard to know what is what.

// The type expresses the unit. Best solution.
let interval: Duration = Duration::from_millis(1001);

// The variable expresses the unit. Good solution for when the type can't or should not express the unit.
let interval_ms: u64 = 1001;

// Neither expresses the unit. Very hard to read, understand and properly use:
let interval: u64 = 1001;

faern avatar Jul 23 '20 10:07 faern