Best practices of using const

envoid envoid at cool-mail.com
Wed Feb 13 11:32:46 UTC 2019


In C++ we have const correctness in some way. A compiler can make 
optimizations whenever it doesn't find a const_cast and the 
mutable specifier marks members that aren't a part of the object 
state. Of course, it's not perfect but one can document their 
intentions and it's possible to use synchronization primitives 
without an issue. On the opposite side, D has a stricter 
(transitive) const and it's almost useless in many cases. Is 
there an article that explains best practices of using const in 
D? The statement "In C++ const isn't transitive so we fixed 
that." alone isn't convincing. The only way I see right now is 
omitting the const keyword completely which is ridiculous.


More information about the Digitalmars-d-learn mailing list