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


Tue Nov 22 23:43:50 UTC 2022


On Tuesday, 22 November 2022 at 23:30:38 UTC, thebluepandabear 
wrote:
> On Tuesday, 22 November 2022 at 22:40:54 UTC, []() {}() wrote:
>> On Friday, 18 November 2022 at 11:51:42 UTC, thebluepandabear 
>> wrote:
>>>
>>> As a newcomer, I'd be interested in hearing everyones 
>>> thoughts.
>>
>> Everyones thoughts? You sure about that ;-)
>>
>> anyho....
>>
>> To Const or Not to Const?
>>
>> https://www.artima.com/articles/const-rtti-and-efficiency
>
> C++ const is different than D const, not sure how helpful that 
> article is.

Yes, that is true (about the differences).

But Scott is very specific about it not being langauge specific. 
His guidelines are engineering guidelines.

e.g. "You're saying in your experience, the cost of the policy to 
type const all those times just doesn't pay for itself. If that's 
been your experience, then that's fine."

In other words, he is saying, the decision to use const or not, 
is a tradeoff.

Software engineers make tradeoffs, all the time. It comes with 
package.

So the answer to your question is, use it when it has a payoff - 
for you.

That's the same answer I gave to you for getters/setters ;-)



More information about the Digitalmars-d-learn mailing list