const as default for variables

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Mar 15 00:44:12 PDT 2015


On 3/14/2015 10:23 PM, deadalnix wrote:
> On Sunday, 15 March 2015 at 05:08:54 UTC, Walter Bright wrote:
>> On 3/14/2015 8:50 PM, deadalnix wrote:
>>> Const is the inconvenience of immutability without its benefit. That would be a
>>> poor default, IMO.
>>
>> It's utility is in self-documenting encapsulation.
>>
>> It also turns out that it offers optimization possibilities for ARC systems.
>
> You'll have to explain yourself, as there is nothing obvious here.
>
> I see how immutable can be leveraged to optimize, but I don't think const offers
> the same capabilities.

"const ref" can tell the optimizer that that path for a ref counted object 
cannot alter its ref count.


More information about the Digitalmars-d mailing list