6.170 / Spring 2001 / Lecture 6 Card Answers

Handout L6-QA


Question: How do you deal with a specification such as:
/**
 * @effects: returns a random int
 **/
int foo ();
Would the implementation
int foo() {
  return 3;
}
satisfiy it?
Answer: This example serves to highlight how unclear English can be at times. It really depends on what the specifier meant by "random"; if the intention was to return an arbitrary int, then returning 3 is a perfectly good implementation. If, however, the specifier wanted a random integer (i.e. something that would produce a sequence of values with non-zero variance) that changed from one invocation to another, than returning 3 would not satisfy the spec. In short, the spec was unclear.

Question: I don't understand the difference between cohesion and coupling.
Answer: In lecture cohesion was used to describe how well a certain module in a program fits together. All of the operations should be related and the module should function cleanly and make sense as a unit. Coupling was used to describe the connection between different modules. These connections tend to be fewer and looser and generally are desired to be kept to a minimum.

The words really aren't that important; the real point was that a well designed system contains many components. Most of the interactions in the system should be between parts of a given component, and the number of interactions between separate components should be much fewer.

Question: Can we treat all of the specifications we write as being restricted to the domain specified by the requires?
Answer: Of course. That's the whole point to having a requires clause. :)

Question: When is one spec stronger than another?
Answer: One spec is strong then another when it permits fewer implementations. Essentially if all possible implementations of spec A are also valid implementations of spec B, then spec A is stronger than spec B.

Question: When does a transition set satisfy a specification?
Answer: When the transition set for an implementation is a subset of the transition spec for a specification then the implementation satisfies the spec.

This could becoming confusing, however, if you consider the specifications transition set to only include transitions for the cases when the precondition was valid. If, however, you include in the specification all transitions from any state with an invalid precondition to any state whatsoever, then any implementation which has a transition set which is a subset is a valid implementation.


Back to Index Card Answers.
Back to the 6.170 home page.
For problems or questions regarding this page, contact: 6.170-webmaster@mit.edu.
$Id: lec06-qa.html,v 1.3 2001/02/28 14:39:54 mernst Exp $