Peter Shenkin writes:
> Hi,
>
> What's the purpose of having assert, require and ensure, when they
> all do the same thing?
>
> I know a rose by any name would be just as sweet, but by three names
> it wouldn't be three times sweeter....
In Fortran, it's just additional documentation about the exact intent
of the assertion. In Eiffel, preconditions and postconditions for a
base class can be separately relaxed or strengthened in derived
classes. They are used together to maintain class invariants.
Quoting from Meyer, Object-Oriented Software Construction (2nd
edition), section 11.5:
"The precondition states the properties that must hold whenever the
routine is called; the postcondition states the properties that the
routine guaranties when it returns."
So I expect I'd have a clump of REQUIRES at the start of a
subroutine, and a clump of ENSURES at the end. If I'm doing
a one-off, and I'm tired of locking the caps key, I'll just type
assert.
Regards, Phil
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|