Why isn't purity & co. inferred for all functions?

Alex Rønne Petersen xtzgzorex at gmail.com
Sat May 12 03:19:34 PDT 2012


On 11-05-2012 20:53, Trass3r wrote:
> It's already inferred for templated functions, so it's perfectly possible.
> Also it should be checked anyway, so I get an error message if I marked
> something pure or whatever while it actually isn't.
>
> The only functions where it can't be inferred and manual attributes are
> really needed are function definitions (i.e. no body available).
>
> What speaks against it?

Purity is part of the API. If, in version $a of an API, your function 
just happens to be inferred as pure and your users rely on it, you'll 
break their code if you change your function's code in version $b and 
it's no longer pure without you noticing. This effectively defeats the 
purpose of inferred purity because you cannot rely on it.

It's as simple as that.

-- 
- Alex


More information about the Digitalmars-d mailing list