Why is `scope` planned for deprecation?

via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 13 05:36:14 PST 2014


On Thursday, 13 November 2014 at 12:01:33 UTC, Ola Fosheim 
Grøstad wrote:
> On Thursday, 13 November 2014 at 11:44:31 UTC, Manu via 
> Digitalmars-d wrote:
>> I don't follow how you associate that opinion with 
>> implementation of
>> scope.
>
> I don't like semantics where I have to state that the 
> parameters and the function should be "pure". It should be 
> opposite. Say, if you have an array on the stack, then I'd like 
> to take a slice of it and send it to a function to compute a 
> sum(). But, I don't want the type system to prevent me from 
> doing it because the author of sum() forgot to add "scope" to 
> the parameter.
>
> What is the difference between a function that is annotated as 
> "pure" and a function where all input is "scope"? This is 
> backwards!
>
> Function signatures should not say "I am playing nice…", that 
> should be the default. They should say "watch out, I'm stealing 
> your stuff!".

I agree with this in principle, but it is unrealistic for D2. 
This is stuff that can go into a future D3, together with @safe 
by default, pure by default, and maybe immutable by default. But 
that doesn't mean that it shouldn't be introduced in D2 already, 
so that we can gain experience with it.

That said, it might not be so bad with `scope`. The latest 
iteration of the proposal has been simplified a lot; scope 
annotations will mostly be needed for function signatures, and 
explicit owners are only allowed there. There's also some 
potential for inference with templates.


More information about the Digitalmars-d mailing list