Opportunities for D

via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 10 13:57:07 PDT 2014


On Thursday, 10 July 2014 at 20:41:55 UTC, Walter Bright wrote:
> On 7/10/2014 11:53 AM, Timon Gehr wrote:
>> Are you talking about the concept, the examples, or just the 
>> last example? What
>> makes it seem complicated?
>
> I can't imagine users going to the bother of typing all that, 
> let alone what happens when they do it wrong. Most users don't 
> really have a good handle on what the lifetimes of their data 
> are, so how are they going to annotate it correctly?

It doesn't need to be specified manually everywhere:

* For templates, it can be inferred.

* Local variables are either the objects _to which_ references 
are borrowed, in which case no annotation is necessary, or the 
contain returned values from functions, in which case `auto` can 
be used.

* Even most methods and library functions can just mark their 
parameters as `scope` (or whatever the syntax will be), without 
any mentioning of a lifetime or owner.

That leaves relatively few cases where either a reference to a 
passed-in parameter is returned (e.g. typical haystack-needle 
operations), or (more unusual), a passed in value is being kept 
around temporarily, e.g. as a member of a struct.

This could be reduced even more for pure functions, where the 
compiler can automatically allow borrowing if it's clear from the 
parameter and return types that no reference to the argument can 
be escaped.


More information about the Digitalmars-d mailing list