First Draft: Static Single Assignment
Peter C
peterc at gmail.com
Sun Nov 16 04:16:56 UTC 2025
On Sunday, 16 November 2025 at 03:12:08 UTC, monkyyy wrote:
> On Sunday, 16 November 2025 at 02:43:03 UTC, Richard (Rikki)
> Andrew Cattermole wrote:
>> Three things I'd like to see here:
>>
>> 1. Function parameters
>>
>> 2. Fields
>>
>> 3. Globals
>
> ```d
> struct writeonce(T){
> final T data;
> final bool hasBeenSet;
> auto opAssign(T data_){
> assert( ! hasBeenSet);
> return data=data_;
> }}
> ```
>
> ---
>
> `void foo(ref final int a)` it would need to be ref to do
> anything
This use of 'final' .. me no like!
Seeing 'final' makes me immediately think about inheritance and
method overriding.
That extra disambiguation required here, increases my cognitive
load - which me also no like!
Just the use of this overloaded term 'final' turns me off any
proposal that wants to use it - yet again!
An explicit keyword that communicates directly one thing, and one
thing only - "assign once during construction", will make the
code's meaning both immediate and unambiguous.
Keywords should communicate intent directly.
I propose intead, 'init' - it (at least to me) directly evokes
an initialization context for the construction of a variable.
This is not bikeshedding. It's not trivial nitpicking. Choosing
the right primitive here needs to be a well thought out design
decision.
'final' would almost certainly negatively affect cognitive load,
and the programmers ability to quickly reason about code - not to
mention 3rd party tools.
Any proposal using that overloaded term 'final' will get the
thumbs down from me.
More information about the dip.development
mailing list