Is there any real reason to use "const"?

Patrick Schluter Patrick.Schluter at
Mon Jan 24 20:26:03 UTC 2022

On Monday, 24 January 2022 at 16:23:25 UTC, rempas wrote:
> On Monday, 24 January 2022 at 14:22:55 UTC, Guillaume Piolat 
> wrote:
>> const has utility at interface boundaries. You don't want an 
>> API to be used incorrectly.
>> If it's internal code though, it only helps the maintainers, 
>> and is often line noise.
> I mean, I can understand and agree the cases where people will 
> just make mistakes because they are humans or because they are 
> coding at a time they should be sleeping but like I said, I 
> think that why should start writing good documentation and 
> people should start reading it. Thanks for your thoughts!

No, at API level it is also a documentation help. When a 
parameter is marked as const, the code reader can be sure that 
there are no side effects in that function on that parameter. 
This reduces the mental burden when one tries to read code.

More information about the Digitalmars-d mailing list