Guard ClauseThe book has now been published and the content of this chapter has likely changed substanstially.
How do you format code that shouldn't execute if a condition holds?
Enforce preconditions of method body by returning immediately if unsatisifed.
Format the one-branch conditional with an explicit return.
Guard Clause lets us "get out quickly" when there are multiple reasons for not executing a method body. Each Guard Clause verifies one of the pre-conditions of the method has been met.
Further ReadingParaphrased from Kent Beck's book "Smalltalk Best Practice Patterns" [SBPP].
Copyright © 2003-2008 Gerard Meszaros all rights reserved