Prototype of Ownership/Borrowing System for D

Johannes Pfau nospam at example.com
Thu Nov 21 20:30:54 UTC 2019


Am Thu, 21 Nov 2019 03:10:28 -0800 schrieb Walter Bright:

> On 11/21/2019 12:18 AM, Johannes Pfau wrote:
>> TypeScript does that. In addition, it disallows dereferencing if the
>> pointer is in the undefined state. So it forces you to check a pointer
>> before you dereference it. I always found that to be quite useful.
> 
> I would find that to be annoying, as the CPU hardware checks it before
> dereferencing it, too, for free.

As Ola mentioned it's most useful as part of a complete flow-typing 
system and much of the benefit in TypeScript is also caused by having 
nullable and non-nullable types:

void foo (Nullable!T value)
{
    if (value)
        bar(value);
    else
    	bar2();
}

In the call to bar, value is known to be not null, so the type is no 
longer Nullable!T but T instead. So essentially, this provides a natural 
way to safely go from nullable to non-null types. Heavy use of non-null 
types makes sure you don't have to insert if () checks just to satisfy 
the compiler. In TypeScript the amount of false positives for this error 
message actually seemed to be quite low.

-- 
Johannes


More information about the Digitalmars-d mailing list