Article: Why Const Sucks

Adam D. Ruppe destructionator at gmail.com
Mon Mar 5 13:59:02 UTC 2018


On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote:
> Here's something I wrote up on const:


So as to the  main thrust, I generally agree. In fact, I think 
const is almost useless even if you want to use it fully: you 
said immutable is better in many places, and yes, but in addition 
to that, inout is better than const in most the remaining cases.

Constructing a const variable? Almost completely useless - 
immutable is better in almost all (if not actually all) cases. 
Referencing function parameters? inout is better in all cases 
except just plain input. If there's any part of it being returned 
- as is the case on most member methods to me at least - inout is 
flat-out better.

And then, of course, like you said "don't use it" is the solution 
to most of the const system's flaws anyway.... which seems to be 
the case with a lot of D's add-on qualifiers.


More information about the Digitalmars-d-announce mailing list