`@safe` by default. What about `@pure` and `immutable` by default?
Atila Neves
atila.neves at gmail.com
Tue Apr 16 12:34:14 UTC 2019
On Tuesday, 16 April 2019 at 03:59:38 UTC, 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 think that `@safe` and `pure` should be the default, but not
`immutable`. It's too restrictive. I'd make it `const` by
default. I'm not *too* bothere about it though, because I have to
write something before the variable's name to declare it anyway,
so I myself just default to writing `const` instead of `auto`.
The exception in nearly every case that isn't dealing with a
dependency that isn't const-correct is ranges.
As mentioned elsewhere on this thread, for `pure` to be the
default we need to be able to negate it.
More information about the Digitalmars-d
mailing list