5 ms·
The author says, "That Go uses arbitrary-precision for constant expressions seems dangerous to me." Why? My thoughts: 1) more inefficient programs because enc
by spencerwgreene 8y ago
The author says, "That Go uses arbitrary-precision for constant expressions seems dangerous to me."
Why?
My thoughts:
1) more inefficient programs because encountering an arbitrary-precision expression requires arbitrarily large memory and computation,
2) more complicated language implementation.
- banthar 8y agoConstant expressions are evaluated at compile time. Compilation would suffer any eventual performance penalties. This probably makes the compiler simpler - no need to implement different arithmetic for different types & no need to guess the types. The dangerous bit is, that just extracting a variable from constant expressions might change the result slightly. That should not be a problem, unless you are depending on exact values.
- int_19h 8y agoThe dangerous part is that now the value of the computation can change slightly if it's no longer constant. So e.g. if it involves a named constant, and that constant then becomes a variable for some reason (e.g. because it now needs to be computed at runtime, because it varies from platform to platform), you can end up with broken code with no warning.
- geocar 8y ago> Why? Hint 1: Can you imagine ever moving a magic number from an expression into a constant?