Logical Const

An algorithm, procedure, or operations is logically const if it does not alter the logical state of an object or type. Note that this is a looser property than PhysicalConstness (the bits don't change). LogicalConstness is useful in several cases:

It is easy for a compiler to determine whether or not the bits change. It is harder to determine whether or not the logical state of an object changes; for this reason implementing LogicalConst often requires holes be left in the typing system. Two ways to do it are:

A good rule of thumb for LogicalConst is as follows: If an operation preserves LogicalConstness, then if the old state and the new state are compared with the EqualityOperator, the result should be true. In other words, the EqualityOperator should reflect the logical state of the object. I know of no language which enforces this...

-- engineer_scotty (Scott Johnson)

Enforcing logical const in the face of mutable is computationally intractable. You could do some UnitTests, but that is about as far as it can go.


CategoryLogic


EditText of this page (last edited January 1, 2005) or FindPage with title or text search