Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That Rust constant named CONSTANT, is an actual constant (like an old-school #define) whereas in C++ what you've named CONSTANT is an immutable variable with a constant initial value that the language promises you can refer to from other constant contexts. This is a subtle difference, but it's probably at the heart of how C++ programmers end up needing constfoo, constbar, const_yet_more_stuff because their nomenclature is so screwed up.

The VARIABLE in Rust is an immutable static variable, similar to the thing you named CONSTANT in C++ and likewise it is constant evaluted so it happens at compile time, there is no "may or may not" here because the value is getting baked into the executable.

If we want to promise only that our mutable variable is constant initialized, like the C++ VARIABLE, in Rust we write that as:

    let mut actually_varies = const { bar() }; // Guaranteed to be evaluated at compile time
And finally, yes if we write only:

    let mut just_normal = bar(); // This may or may not be evaluated at compile time
So, I count more possibilities in the Rust, and IMNSHO their naming is clearer.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: