Worst ideas/features in programming languages?
Wed Dec 29 08:10:42 UTC 2021
On Wednesday, 29 December 2021 at 05:09:33 UTC, Walter Bright
> 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.
>> 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. What's the use case for it?
The typestate  design pattern. In languages that support some
form of affine types  like Rust (*), this design pattern can
be used to prevent classes of programmer errors at compile-time,
while the best C++ and D can do is use `assert` at run-time to
facilitate detecting them. Here's a few articles that showcase
this in Rust:
(*) Technically, affine types are about using a variable at most
once. In Rust, if a type doesn't implement the Copy / Clone
traits , variables of that type have move semantics - that is,
they can't be used after they have been passed to a function that
takes them by value (passing ownership). But they can be still
passed multiple times to functions take them by reference
More information about the Digitalmars-d