3 ms·
> All of this means that const actually provides zero guarantees about an object not being mutated (and even in the case where the object is directly constructe
by signa11 9y ago
> All of this means that const actually provides zero guarantees about an object not being mutated (and even in the case where the object is directly constructed as const, that just means that it's undefined behavior when the object is mutated, not that the compiler actually protects against it being mutated).
if this is the only reason why author thinks that const is a problem, then it is all good. you can do the same thing in C as well. and ofcourse, if you do that, and break things, you get to hold all the pieces as well :)
probably a 'constexpr' semantics is what the author might be looking for ?
arne-mertz article on mutable, available here: https://arne-mertz.de/2017/10/mutable/ https://arne-mertz.de/2017/10/mutable/, which imho, is another side of the const-coin, is quite good as well.
edit-001 : slight change.
- gorgonical 9y agoI agree. Even extremely safe languages like Ada, which have found most of their use in safety-critical situations like in plane avionics and medical equipment, allow the programmer to do "unchecked conversions," the equivalent of a static_cast. It would actually be insane for const to forbid the programmer from doing any of these things. A certain amount of a language and its features is to protect your program from other programmers, to communicate your idea and vision about the code. In that way, const is amazingly useful.
- signa11 9y ago> A certain amount of a language and its features is to protect your program from other programmers, to communicate your idea and vision about the code. indeed ! language is about telling others (and yourself) about ideas that you want to express. c and c++ seems to be more suited for 'consenting adults' (oh dear) than anything else :)