5.2. How Testing Will Make You a Better Developer

If each and every one of us accepts personal responsibility for the quality of our code, most of these problems will go away. Granted, this is easier said than done. For all of the reasons previously discussed, it can be much more rewarding to write more features at lower quality and hope that either nobody will notice or that somebody else will deal with the bugs later. However, the rewards of taking responsibility for your own code quality are many and varied.

5.2.1. Your Designs Will Be Better

Writing tests, whether before or after you write your code (although before is still better; see Chapter 2, "Test-Driven Development"), will force you to use your own interfaces. Over time, the practice of consuming your own interfaces will lead you to design better, more usable interfaces the first time around. This is particularly true if you write libraries that are used by other people. If you write libraries that expose features you think are important but never try to use those libraries, the design will suffer. The way you picture the library working may not be the most practical way to write the code from your consumer's perspective. Writing tests will force you to see both sides of the equation, and you will improve the design of your code. If you write the tests first, you won't have to go back and fix your code later. If you wait until you are done before writing your tests, you may have to go back and make some changes to ...

Get Code Leader: Using People, Tools, and Processes to Build Successful Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.