5 ms·
`const` is for compile-time constants where something like `let` in Rust can be used for values generated on the fly. The latter is immensely more powerful and
by AndreasFrom 12y ago
`const` is for compile-time constants where something like `let` in Rust can be used for values generated on the fly.
The latter is immensely more powerful and actually provides the described benefits like guaranteeing that data is not changing under your feet.
Edit: While `const PI = 3.1415…` is threadsafe, it's not very useful in comparison to runtime-immutability :)
- andrejewski 12y agoYes, the guarantees provided by true immutability are not met by "const". I wrote the note loosely using the author's expectations and advantages of immutability, not the exact definition. But thank you for letting me clarify. Also I just noticed with Go's Unicode support we can write `const π = 3.14..` if we really wanted.