Why aren't function attributes inferred?
Jonathan M Davis
jmdavisProg at gmx.com
Sat Aug 20 17:23:44 PDT 2011
On Saturday, August 20, 2011 16:50:32 Sean Eskapp wrote:
> Since the compiler can clearly tell when a function is not const, safe,
> pure, or nothrow, why can't they just be assumed, unless proven otherwise?
As of 2.054, @safe, pure, and nothrow are inferred for delegates and templated
functions. This is because whether they can be @safe, pure, or nothrow depends
entirely on the types that they're instantiated with. For normal functions,
there is no such inferrence. It's not needed.
As for just assuming attributes, the language was designed like pretty much
every other C-based language (C++, Java, C#, etc.) in that unless a function
is marked with an attribute, it doesn't have that attribute. It _could_ have
been designed the other way around, but then all of your attributes become
stuff like mutable, impure, and throw. It doesn't really buy you anything. It
just changes what attributes you have to mark stuff with. And whether you'd be
using more attributes or fewer attributes with such a scheme would depend
entirely on the code. But such a scheme would be entirely foreign to most
programmers of C-based languages.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list