Google Testing Blog: Code Health: Reduce Nesting, Reduce Complexity
Answer: the "wrong encoding" and "unauthorized" errors are swapped. This bug is easier to see in the refactored version, since the checks occur right as the errors are handled.The refactoring technique shown above is known as guard clauses. A guard clause checks a criterion and fails fast if it is not met. It decouples the computational logic from the error logic. By removing the cognitive gap between error checking and handling, it frees up mental processing power. As a result, the refactored version is much easier to read and maintain.
Read full article from Google Testing Blog: Code Health: Reduce Nesting, Reduce Complexity
No comments:
Post a Comment