Uh... destructors?

%u wfunction at hotmail.com
Tue Feb 22 11:31:30 PST 2011


I just visited Wikipedia (savior of the day) and a quick look at
this article:
http://en.wikipedia.org/wiki/Pure_function

yields the following requirements for a pure function:

1. The function always evaluates the same result value given the
same argument value(s). The function result value cannot depend on
any hidden information or state that may change as program execution
proceeds or between different executions of the program, nor can it
depend on any external input from I/O devices.

2. Evaluation of the result does not cause any semantically
observable side effect or output, such as mutation of mutable
objects or output to I/O devices.

"pure" destructors always fail the first test, because they clearly
cause a state change for the current object, if not for a global
resource like memory. Pure functions need to be timeless and can be
freely reordered; a destructor call, however, is not timeless -- it
depends on the current state of the object, and the changes it makes
are visible to the outside world.

They also usually fail the second test, because if, for example, we
flush a file inside a destructor, that clearly has an observable
output... so I can't see why a destructor would ever be pure.


More information about the Digitalmars-d mailing list