`@safe` by default. What about `@pure` and `immutable` by default?
Seb
seb at wilzba.ch
Fri Apr 19 13:09:50 UTC 2019
On Friday, 19 April 2019 at 12:23:08 UTC, Andrei Alexandrescu
wrote:
> On 4/15/19 11:59 PM, Mike Franklin wrote:
>> I think I may have found a simple migration path to @safe by
>> default. I'm still thinking it through, but if I can justify
>> it, I will write a DIP.
>>
>> `@safe` by default is a no-brainer in my opinion, but `pure`
>> and `immutable` by default are less obvious. With the
>> aforementioned potential DIP, I have an opportunity to correct
>> purity and mutability defaults as well...but is that something
>> we want to do?
>>
>> Can anyone save me some trouble and articulate why it would be
>> bad to have `pure` and/or `immutable` by default?
>>
>> Thanks,
>> Mike
>
> I haven't participated much to this but here's a thought. This
> migration is again in the category "let's change things and
> evaluate the costs". It is so much better to go with "let's add
> and enjoy the benefits".
Most D code is yet to be written. Safe by default is sth. that
all new D code should be
> It's cheap to make @safe and pure the defaults for a given
> module. Plant this at the beginning:
>
> pure: @safe:
NOPE. That doesn't work as DMD doesn't set pure for member
functions.
---
pure:
struct Foo {
int bar() { return 42; }
}
void main()
{
Foo().bar(); // Error: pure function D main cannot call impure
function onlineapp.Foo.bar
}
---
https://run.dlang.io/is/cgESWs
More information about the Digitalmars-d
mailing list