First Draft: Static Single Assignment

Peter C peterc at gmail.com
Sat Dec 6 23:46:45 UTC 2025


On Saturday, 6 December 2025 at 11:45:21 UTC, Nick Treleaven 
wrote:
> On Friday, 5 December 2025 at 23:25:41 UTC, Peter C wrote:
>> also, if final is ever going to work with class fields, then 
>> if default initialization is considered an assignment, then 
>> you won't be able to write code like this:
>>
>> class Config
>> {
>>     final int port; // declared, default initialized to 0
>>
>>     this(int p)
>>     {
>>         port = p; // explicit assignment - allowed once.
>>     }
>> }
>
> No, read https://dlang.org/spec/class.html#field-init. That's 
> initialization.

So, 'technically' I stand corrected again.

But regardless of this semantic distinction, the first instance 
of the **assignment** operator (=) to a final variable is the one 
that permanently **assigns** its value.

The mental model of 'assignment is the operation performed by the 
assignment operator', is conceptually cleaner to me. There is 
absolutely no need for my brain to decide whether I'm actually 
initializing or assigning; it just adds no value, in this 
context, to the practical task of writing correct code.



More information about the dip.development mailing list