How do you do "const nazi" in D?

Mark smarksc at gmail.com
Thu Jan 4 13:52:14 UTC 2018


On Wednesday, 3 January 2018 at 17:27:38 UTC, Marc wrote:
> for a safe programming, since C/C++ times I try to make thing 
> const as possible. locals, parameters etc anything which isn't 
> going to change.
> How do you do that in D? immutable everywhere?
>
> for example:
>
>>	foreach(Field field; fields) {
>>		immutable string htmlOutputfile = genHTMLFilename();
>
> do you use immutable here?
>
> and on:
>
>> Field fromFile(in string filename) {
>
> do you use in here if filename isn't going to change?
>
> I'm trying to make my own const nazi guide for D, if anyone 
> would like to give your opinion on this, I would be glad.

You ma find Ali Cehreli's talk from DConf 2013 [1] useful. It 
includes some guidelines (basically recommendations) on how to 
use immutable and const.

[1] https://www.youtube.com/watch?v=mPr2UspS0fE


More information about the Digitalmars-d-learn mailing list