Top critical review
12 people found this helpful
Not enough material
on March 9, 2006
The aim of the book is to teach readers about contracts and how to write good ones. The main points are summarized at the start of the book in a series of six guidelines (as described in the review above):
- Separate queries from commands
- Separate basic queries from derived queries
- Write a postcondition for each derived query that specifies what result can be returned
- Write a postcondition for each command that specifies the value of every basic query
- Decide on a suitable precondition for every query and command
- Write invariants to define unchanging properties of objects
This part is well written and provides good advice for people new to writing contracts. The presentation is however very academic with examples based on stacks and dictionaries.
The authors then try to present more realistic examples. Unfortunately that's where they fail badly.
The first example shows how to use contracts to write an observer pattern. The only thing that the authors show is that you can write a contract that makes sure that the observers are properly added to the list of observers. Since most modern languages implement the observer pattern in the language itself (via events), this is a contract that no-one needs to write. The problem that usually happens in real programming is that the events are wired up too early or too late. Contracts provide little help for this. The authors should have chosen an example that better demonstrates the power of contracts.
The second example is an over-extended explanation about how you can write code so that you never call a method when its precondition is false. The explanation is convoluted and offers no real insight into programming by contracts.
The final chapter discusses applying contracts to languages that do not support them natively (basically all languages other than Eiffel). I had high hopes for this chapter. Unfortunately, the authors recommend using a pre-processor (e.g., iContracts) or only implementing preconditions with assertions. Most programmers with a little experience will already be using assertions and will not learn much from the chapter.
The book is a compilation of various papers that the authors published in conferences (mainly TOOLS). The problem is that the material is suited to a 20 page paper not a 200+ page book. Even with repetitions and ample space the lack of useful information is apparent. The second half of the book is a waste of paper.
Contracts are a very useful tool when properly applied. The guidelines presented at the start of the book are very good. Unfortunately the book is marred by a lack of real world examples.