Friday, April 16, 2010

Growing object-oriented software review

Growing Object-Oriented Software, Guided by TestsGrowing object-oriented software, guided by tests is a masterpiece on Test-Driven Development, a valid guide for the beginner in this field and for the almost expert as well. This book guides the reader through a world where TDD is not only always applied, but it is kept in its pure form.
The title describes exactly the purpose of the practices presented in the book: starting an ambitious project from scratch, and expand the product from an empty skeleton to a fully-featured application. Unit, integration and acceptance tests are the specifications which are written before the production code, and that drive the development in an agile way towards a the end of an iteration or a release.

The book is divided in five parts:
  • Introduction to Test-Driven Development and design principles for object-oriented applications. This part bridges the beginner with the rest of the book, written for a programmer at an intermediate level.
  • The process of Test-Driven Development: TDD in a double cycle, mocking, third-party code, and every bit of theory you need to know about Red-Green-Refactor.
  • A worked example: 150 pages where the authors build from scratch an application which interfaces with the web and a user interface, by adding one test at the time and justifying every single step. The code is available in different programming languages on the official web site.
  • Sustainable Test-Driven Development: TDD is often abandoned when issues arise due to its incorrect usage. Managing the test suite is the most important part of long-term maintainability and readability, expressiveness and consistency are taught here.
  • Advanced topics: persistence, threading and asynchronous calls are often a difficult field for test-driven applications, enhancing the omnipresent danger of introducing brittle and slow tests. Though, it is not impossible to extend testing in these areas by tweaking the original approach. Remember that if you code test-first, nothing can stop you from writing testable code.
As you can see from the Advanced topics part, the book is oriented to a Java audience, but if you exclude the last two chapters every practice and principle is just tied to real object-oriented programming and not to particular programming languages. For examples, PHP 5 has a complete object paradigm and the necessary tools (PHPUnit, Zend_Test) to practice the techniques described in the book.
A basic knowledge of Java helps, though, because the code samples are written in Java and make use of frameworks such as Swing; of course JUnit-based tests are instead perfectly equivalent to test written with any other xUnit testing framework.

Some concepts explained by this book - such as the Walking Skeleton and Acceptance TDD - were very enlightening. I guess there is a reason why Misko Hevery recommends this book:
Reading the book I sometimes felt that I was listening to myself, especially when the authors warned about global state, singletons, overusing mocks, and doing work in constructors among other things. But unlike myself, who draws sharp lines between right and wrong, the authors did a good job of presenting things on the gray scale of benefits and drawbacks. The book shows what a typical code most people will write, and then show how tests point a way towards refactoring.
Also Robert C. Martin, also known as Uncle Bob, has words of praise for Growing object-oriented software:
At last a book, suffused with code, that exposes the deep symbiosis between TDD and OOD. The authors, pioneers in test-driven development, have packed it with principles, practices, heuristics, and (best of all) anecdotes drawn from their decades of professional experience. Every software craftsman will want to pore over the chapters of worked examples and study the advanced testing and design principles. This one’s a keeper.
I am glad I have finished reading it before starting my thesis on a large project. If you do not trust me, trust them. :)


Carlo Scarioni said...

Half way reading the book. And althought i think it's great, i get lost in the example sometimes. I think that this is the kinda book that you should write the examples as you read it.

Giorgio said...

When reading hands-on books the best choice it's to have a personal project to develop in parallel to the case study treated in the book. That way you can apply what you learn to your own domain, where you are most comfortable. :)