How often I should be using const? Is it useless/overrated?

thebluepandabear therealbluepandabear at protonmail.com
Fri Nov 18 11:51:42 UTC 2022


A question I have been thinking about whilst using D is how often 
I should be using const.

Many people claim that all variables should be const by default, 
but whether or not it is really needed is debatable and 
oftentimes making everything const could cause readability issues 
and make the code more complex.

I also wonder how important const really is, like 99% of the time 
you will know when your variable will be changed, and even when a 
variable changes it's not like it is the end of the world.

Also, there is no real end to how much variables can be const. 
Oftentimes -- interestingly -- in popular repos I don't even see 
const being used, this is what confuses me.

As a newcomer, I'd be interested in hearing everyones thoughts.



More information about the Digitalmars-d-learn mailing list