Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variable naming section on expressing unit of the type #9

Open
faern opened this issue Jul 23, 2020 · 0 comments
Open

Add variable naming section on expressing unit of the type #9

faern opened this issue Jul 23, 2020 · 0 comments

Comments

@faern
Copy link
Member

faern commented Jul 23, 2020

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant