Worst ideas/features in programming languages?
Timon Gehr
timon.gehr at gmx.ch
Tue Jan 4 04:30:56 UTC 2022
On 29.12.21 06:09, Walter Bright wrote:
> On 11/9/2021 11:09 PM, Timon Gehr wrote:
>> On 10/16/21 1:12 AM, Walter Bright wrote:
>>> On 10/12/2021 2:38 PM, Timon Gehr wrote:
>>>> - non-lexical variable lifetimes (probably not happening)
>>>
>>> It's already implemented for @live.
>>
>>
>> Specifically, I would like it to influence scoping.
>>
>> ```d
>> int x=2;
>> int y=move(x);
>> int z=x; // error: undefined identifier x (was moved away)
>
> @live currently does that for pointers, but not for non-pointers.
It removes the variable from the scope? (And anyway, @live is a function
annotation, which makes little sense.)
> What's the use case for it?
> ...
This is just how moving things works. If you move it, it's no longer
where it was. If the variable disappears, we don't have to bother with
putting `x` into some safe default state. Some types can't even
naturally support a safe default state. The simplest example is indeed a
`struct` implementing a unique non-null pointer managing its own memory.
(By whatever means you want, it does not even have to have any pointer
members to implement such semantics.)
>
>> int y=move(y); // ok
>> ```
>
> I see what you mean, but since D disallows:
>
> int x; { int x; }
>
> which prevents a number of bugs, so I can't see allowing that.
I don't see how that's related. It's two variables `y` whose lifetimes
do not overlap. It's more like this:
{int x; } { int x; }
Which D allows.
More information about the Digitalmars-d
mailing list