The effects clause specifies the behavior of the method when its requires clause is satisfied. We can associate a truth value with an effects clause, which basically answers the question "Does the implementation have these effects?" In order for an implementation to satisfy its specification, the effects clause must be true. So, if an effects clause is "true", then any implementation satisfies this. In other words, the procedure can do anything it wants. If an effects clause is "false", then no implementation satisfies the specification.
Question: Could you explain the strongest
requires/effects/modifies clauses?
Answer: As described above, a requires clause of "true" means
that the implementation cannot assume anything about the arguments or
program state. This is the strongest requires clause because any
other requires clause will be satisfied by fewer program states. For
instance, a requires clause of x != null (where x is some
argument) will not be satisfied for any procedure call where x ==
null, while the requires clause of "true" would be satisfied in
these calls.
The strongest effects clause is "false". If an effects clause is "false", then the specification can never be satisfied. So this is the hardest specification to satisfy.
The strongest modifies clause is "nothing". If a specification says that something can be modified, then it is also valid if the implementation modifies nothing. This implies that a modifies clause of "nothing" is the modifies clause that the fewest implementation can satisfy.
Question: What does it mean for a spec to be weaker or
stronger?
Answer: Specification A is weaker than specification B if the
implementations satisfying A are a superset of those satisfying B.
For instance, if specification B describes a procedure that sorts
integers in O(n log n) time, and specification A describes a
procedure that sorts integers in O(n2) time, A is
weaker than B. Any O(nlgn) sorting algorithm performs at least as well as an
O(n2) sorting algorithm. So A describes all of
the implementations admitted by B and more. A specification is
stronger if that specification is harder to satisfy -- that is, a
subset of the implementations can satisfy that specification.
Question: Can you re-explain requires => (modifies ^
effects)?
Answer: This is just a mathematical way to express the
statement: If the requires clause of a procedure is satisfied, then
the modifies and effects clauses will be satisfied. "=>" means
"implies", and "^" means "and".
If instead B overrides a() with code of its own, it could not call p().