Go has constant (`const`) type that can be evaluated at compile-time but no const type for something that can only be evaluated at Run time.
Go has constant (`const`) type that can be evaluated at compile-time but no const type for something that can only be evaluated at Run time.
Do you trust yourself to write perfect code 100% of the time ? No? Then padlock it is
Const support in languages never makes all modifications to data accessed through the variable locked out, just the top level, which makes it much more difficult to ensure that the assumptions about immutability hold without constantly doing deep copies or having to double and triple check that your Const definitions are correct.
Const often leads to a false sense of security.
yes and that's fine ? for instance how would you encode a graph operation where you want the graph structure to be immutable and the content of the nodes to be variable?
But I was glad it existed because it enabled a whole set of valuable business automation at the time.
not the object
//Constructor goes here
}Rect r1 = new Rect(1,2);
Is this not sufficient to create an immutable rectangle that I can pass around safely in a multi-threaded code?
Exactly. You can have immutable primitives. You can have immutable classes. And you can combine them to form thread-safe immutable classes.
It's much better to have immutable bindings/references so that nothing that mutates the object can be done through them. Rust does it very well, for example. Even C++ has a good version of this.
Yes, that might be superior but even Java is doing better than Go here.