Hacker News new | past | comments | ask | show | jobs | submit login

Is there a way to enable safe "D" by default, rather than using the `@safe` (what looks to be) modifier?



No. We had a very long discussion about safe-by-default on the forums but failed to reach a consensus.

As I understand it, for safe-by-default to work, either all C libraries would have @trusted D bindings written, or all of them would have to be assumed to be @trusted. Most of the community wanted explicit @trusted annotations, Walter and others favored assuming them to be @trusted (or was it assumed @safe?) was the way to go. So, no safe-by-default at this time. :/


D-lang attributes can be used like a label, so for example you can put at the top of your file:

   @safe nogc:

   auto myFunc() { // do stuff }   
   struct Blah {}
Whatever attributes you use apply to all code in the lexical scope below the colon.

It's useful for structs/classes

  struct MyThing {
    auto unsafeFunc() {}
    
    @safe:
    auto safeFunc1() {}
  }


Kind of, mark `main` `@safe`. The transitivity of safety will ensure that you can only call safe functions, else you will get a compile error.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: