Safe mode in D?
Adam D. Ruppe
destructionator at gmail.com
Fri Oct 18 10:19:16 PDT 2013
On Friday, 18 October 2013 at 17:06:57 UTC, H. S. Teoh wrote:
> But if we're gonna do it, I say we should go all the way:
And make scope the default parameter thingy, and implement it.
God I want some kind of escaping check thing so badly, it is
supposed to work already!
http://dlang.org/function.html
scope: references in the parameter cannot be escaped (e.g.
assigned to a global variable)
But what's interesting here is that references to immutable are
virtually value types; string, or immutable(int)[] *can* be
escaped safely, whereas const(int)[] or int[] might not, they can
be overwritten elsewhere (the case now) and can also be freed
elsewhere (if you don't use the gc on them). An immutable
reference would necessarily use the gc, since otherwise it isn't
really immutable.
So you can store immutable stuff in a global or anything and
that's perfectly ok, so scope immutable == immutable. scope const
is different though.
> I'm not as sure about making nothrow default.
i think throwing is really the default anyway just writing normal
D. If we sampled 100 random D functions, I think we'd find most
of them are @safe in practice, even if not marked, and probably
throw too. So that'd be the sane default.
More information about the Digitalmars-d
mailing list