DMD 1.029 and 2.013 releases (automatic pure detection)

Bill Baxter dnewsgroup at billbaxter.com
Sun Apr 27 17:19:55 PDT 2008


Bruno Medeiros wrote:
> Bruno Medeiros wrote:
>>
>> And a new FAQ question was added:
>> "Can't a sufficiently smart compiler figure out that a function is 
>> pure automatically?"
>> http://www.digitalmars.com/d/2.0/faq.html#pure
>>
> 
> This FAQ entry was made in response to the suggestion someone made that 
> pure be automatically detected by the compiler.
> 
> But I think the suggestion made wasn't to remove the pure attribute, and 
> make the compiler detect *all* pure functions. One would still be able 
> to use the pure function parameter. That would invalidate points 1 and 3.
> As for 2: well, just don't do automatic pure detection for virtual 
> functions (unless they are final).

Yes that was indeed one of the things I was thinking.
But imagine function A is not declared pure, but just happens to be so.
Programmer B discovers that and starts to rely on it as a pure function.
Programmer of A later makes an enhancement that kills the purity of A, 
but he never intended A to be pure so he doesn't notice or care.
Programmer B updates library and subsequently is heard to utter the 
phrase "!*$#*%^!$&@#".

So I think I have to agree that if you're going to have pure functions 
in a mixed procedural/functional world, then explicit labeling is 
probably unavoidable.

However, it may still be useful to have tools that discover and 
recommend tagging of functions which are in fact pure.  Same goes for 
nothrow.

Anyway, I would really like for there to be some way to gain the 
benefits of these attributes without me having to think about it.  There 
are already more than enough dimensions of the problem space to keep in 
mind when writing programs without adding more, like pure and nothrow do.

--bb



More information about the Digitalmars-d-announce mailing list