Prototype of Ownership/Borrowing System for D

Johannes Pfau nospam at example.com
Thu Nov 21 08:18:56 UTC 2019


Am Thu, 21 Nov 2019 03:47:21 +0000 schrieb Doc Andrew:

> On Wednesday, 20 November 2019 at 22:15:18 UTC, Walter Bright wrote:
>>
>> I originally was going to add null to the data flow analysis. But I
>> realized it would be rather useless:
>>
>>   T* foo();
>>
>>   T* p = foo(); // is p null or not?
>>
>> Very quickly, the flow analysis would drop into "dunno if it is null or
>> not" so it just won't be worth much.
> 
> You might only have to maintain this "undefined state" for a short
> period of time:
> 
> T* foo();
> T* p = foo();  //Undefined state
> 
> if(p)
> {
>      //We opened Schrodinger's pointer and know it's not null
> anymore.
> }
> else {
>      //We know it's null here.
> }
> 

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.

-- 
Johannes


More information about the Digitalmars-d mailing list