Best practices of using const

Bart Bart at gmail.com
Sun Jun 23 01:27:47 UTC 2019


On Wednesday, 13 February 2019 at 16:40:18 UTC, H. S. Teoh wrote:
> So ironically, the iron-clad semantics of D's const system 
> turns out to be also its own downfall.
>
>

Such things are not ironic. There is always a trade off. You get 
nothing for free in this universe. Physics tells us this. 
Conservation laws apply to energy and everything is energy. Hence 
your computer cannot violate these laws nor can the D 
specification(whatever it ends up meaning) nor can the D const 
system, so to speak...

That is, any time there something is inversely related to 
something else then there will be a conservation relationship. If 
you restrict something too much then something else in direct 
opposition is becoming too unrestricted.

It's not that D's const system is bad, it is that it creates too 
much restriction without any other option. The usual way too 
solve these problems is granularity. this way you can choose the 
right tool for the job.

Maybe D needs different levels of const. constN where constN can 
always be cast to constn for n <= N. One would need to properly 
define the levels to maximize utility and minimize the 
granularity. D probably only needs 3-5 levels to be effective.













More information about the Digitalmars-d-learn mailing list