Generic code: @autoconst, @autopure, @autonothrow

Rainer Deyke rainerd at eldwood.com
Sat Aug 28 21:42:49 PDT 2010


On 8/28/2010 22:33, dsimcha wrote:
>> Is there any real reason why we can't apply these modifiers
>> automatically to all functions?  (And by "real" I don't mean "it would
>> be hard to do" or "it is incompatible with the archaic compilation model
>> chosen by one D implementation".)
> 
> Two reasons:
> 
> 1.  Unless the function is a template, the compiler isn't guaranteed to have the
> source available.  What if it's a binary-only library?

"It is incompatible with the archaic compilation model chosen by one D
implementation."

This special treatment of templates has got to end.

> 2.  The modifiers are part of a contract and part of the public API.  What if some
> function just happens to be pure now, but you consider that an implementation
> detail, not part of its specification?  Client code may rely on this, not
> realizing it's an implementation detail.  Then, when you make the function impure,
> your client code will break.

That may or may not be a compelling argument against always
auto-detecting pure.  It seems stronger as an argument against having
pure as a language feature at all.  (How can you know ahead of time that
a logically pure function will remain physically pure?)


-- 
Rainer Deyke - rainerd at eldwood.com


More information about the Digitalmars-d mailing list