I just got it! (invariant/const)

Janice Caron caron800 at googlemail.com
Wed Apr 9 23:47:49 PDT 2008


On 10/04/2008, Lionello Lunesu <lionello at lunesu.remove.com> wrote:
>  Why? If pure-ness (uh, purity?) can be checked, it can also be deducted

"purity" is the right word. (But "deducted" should be "deduced" :-))

> (*), so the compiler could optimize/complain in either case.

It would slow down compilation no end though. For example, a pure
function is not allowed to call non-pure functions. Without the "pure"
keyword, you'd have to follow through every function call recursively,
and that could take a long time.

Moreover, just because the compiler decides the function is impure,
that doesn't necessarily mean that the programmer /intended/ for it to
be impure. Perhaps there was a bug? Perhaps there was a silly, simple,
one line bug, that the programmer could fix in a jiffy if the compiler
would only say "Error: Line 53: Pure function cannot do XYZ"? It is
far better for the programmer to document their intentions, so that
the compiler can check that those intentions are actually met.



More information about the Digitalmars-d mailing list