3 ms·
In D, we discovered both const and immutable annotations were required. Immutable means the object never changes. Const means the object cannot be altered via t
by WalterBright 5y ago
In D, we discovered both const and immutable annotations were required. Immutable means the object never changes. Const means the object cannot be altered via the const reference, but can be altered by mutable reference to the same object. This makes optimization based on immutability possible, it also means immutable objects can be shared among multiple threads without synchronization.
Both const and immutable attributes are transitive, meaning they are "turtles all the way down." People who are used to C and C++'s non-transitive const find it a bit difficult to get used to; people who have used functional languages find it liberating, and it makes for much easier to understand code.
- fivea 5y ago> Const means the object cannot be altered via the const reference, but can be altered by mutable reference to the same object. Given that this discussion is already going deep into the implementation level, isn't it possible to flag an object as immutable if it's declared and initialized as a const object, or is a const reference to said const object?
- WalterBright 5y agoIf it is declared as const, yes.