RFC, ensureHeaped

spir denis.spir at gmail.com
Wed Nov 17 04:10:20 PST 2010


On Wed, 17 Nov 2010 00:03:05 -0700
Rainer Deyke <rainerd at eldwood.com> wrote:

> Making functions weakly pure by default means that temporarily adding a
> tiny debug printf to any function will require a shitload of cascading
> 'impure' annotations.  I would consider that completely unacceptable.

Output in general, programmer feedback in particuliar, should simply not be considered effect. It is transitory change to dedicated areas of memory -- not state. Isn't this the sense of "output", after all? (One cannot read it back, thus it has no consequence on future process.) The following is imo purely referentially transparent and effect-free (where effect means changing state); it always executes the same way, produces the same result, and never influences later processes else as via said result:

uint square(uint n) {
    uint sq = n*n;
    writefln("%s^2 = %s", n, sq);
    return sq;
}

Sure, the physical machine's state has changed, but it's not the same machine (state) as the one the program runs on (as the one the program can play with). There is some bizarre confusion.
[IMO, FP's notion of purity is at best improper for imperative programming (& at worst requires complicated hacks for using FP itself). We need to find our own way to make programs easier to understand and reason about.]


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list