August 22, 2005 Re: [Vote] Should defining opCmp to be inconsistent with opEquals be an acceptable practice? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon <smjg_1998@yahoo.com> wrote in news:dd3cea$26u7$1@digitaldaemon.com [...] > But there seems to be room for debate on what the best solution is. Possibilities: > > 1. State in the spec that it is an incorrect practice to define opCmp to return 0 if opEquals returns true. [...] Introducing alternative 4: Redesign of overloading operators. 1. In case of singletons also an `opEqual' is senseless and should be accompanied by an implementation with an `assert( 0);' 2. When an `opEqual' makes sense, then it is so basic, that it should be executed prior to the other cases except for performance reasons. 2.a. Therefore an `opNotEqual' should accompany the `opEqual' and the `opCmp' should be synthesized from both along the line: eq= opEqual(); if( eq) return 0; neq= opNotEqual(); if( eq != neq) return neq; else throw new Exception( "Aequivalence not allowed"); 2.b. If the above template is not suitable out of performance reasons the `opCmp' should not be synthesized and replaced by the definition of an `opCmpPerf'. Its then up to the adult programmer to assure the consistency of the design. -manfred |
Copyright © 1999-2021 by the D Language Foundation