I just got it! (invariant/const)

Lionello Lunesu lionello at lunesu.remove.com
Thu Apr 10 01:16:56 PDT 2008


"Janice Caron" <caron800 at googlemail.com> wrote in message 
news:mailman.375.1207810102.2351.digitalmars-d at puremagic.com...
> 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" :-))

:-) thanks.

>> (*), 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.

Yeah, but you'll have to visit those functions anyway, because you're 
compiling. Granted, header files should explicitely mention pure/notpure, 
and to make it safe, it must be mangled.

> 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.

Good point.

L. 




More information about the Digitalmars-d mailing list