@safe by default

Jacob Shtokolov jacob.100205 at gmail.com
Sat Jun 16 13:52:37 UTC 2018


Hi folks,

I know there were a lot of discussions on this topic, and it is 
understandable that due to historical reasons the D language is 
designed with C/C++ interop in mind, so it means that there is no 
@safe by default.

However, I also see a lot of people who want this feature, and I 
personally think that it would be great to have it, because it 
would save a lot of time by marking all functions as @safe by 
default, if it needs to.

It is also understandable that it's not possible to change this 
behavior today, because of compatibility. That's true and that's 
OK to be honest, nothing wrong with it.

I'm still learning D, so please accept my apologies if I don't 
see the whole picture, and if the question is obvious in some 
way, but I'd like to ask:

Is it possible to introduce a new parameter/flag to the compiler, 
to force all functions be @safe by default on a per-module basis?

For example:

```
module mymodule;

pragma(safe);

class Foo {
     // Already marked as @safe by "pragma(safe)"
     void bar() {
         ...
     }
}

// @safe by default
void fooBar() {
     ...
}
```

The same could be done to @nogc and maybe other attributes.

I know that probably I'm not the first guy who proposing that, 
but to be honest, I didn't find any fresh discussion about it, so 
just decided to ask here.

Thanks!


More information about the Digitalmars-d mailing list