3 ms·
> If you want a language where const is the default and mutable is a keyword whats the difference between const and mutable?
by skeezyjefferson 1y ago
> If you want a language where const is the default and mutable is a keyword
whats the difference between const and mutable?
- Thorrez 1y ago"const" means something can't be changed. "mutable" means it can be changed. You don't need both a "const" keyword and a "mutable" keyword in a programming language. You only need 1 of the keywords, because the other can be the default. munchler is saying the "const" keyword shouldn't exist, and instead all variables should be constant by default, and we should have a "mutable" keyword to mark variables as mutable. As opposed to how C++ works today, where there is no "mutable" keyword, variables are mutable by default, and we use a "const" keyword to mark them constant.
- alcover 1y ago> you don't need both a "const" keyword and a "mutable" keyword What if the lang has pointers? How express read-only?
- skeezyjefferson 1y agocompiler flags with line and column number seems like the easiest way
- Thorrez 1y agoYou can make everything read-only by default, and if you need non-read-only, you use "mutable".
- alcover 1y agoYou need two keywords. One for assignability and one for writability : const ptr; // can't reassign, can't write-through (if r/o by default) const mut ptr; // can write