Coder to Developer: Tools and Strategies for Delivering Your Software
| < Day Day Up > |
|
Defensive coding can be the difference between an application that never quite works and one that you can easily maintain and improve. When you’re writing code, you should try to adhere to good defensive coding habits:
-
Use assertions to catch design-time errors.
-
Use exceptions to handle runtime errors.
-
Use exceptions only for exceptional situations.
-
Avoid peppering your code with noise comments.
-
Use comments as placeholders for future work.
-
Use comments to summarize and document the intent of your code.
-
When you change code, make sure you keep the comments up-to-date.
Of course, you need to perform other activities at the same time you’re writing code. One of the most important of these is testing your code. In the next chapter, I’ll introduce unit testing and test-driven development, and show how you can use these tools to help you write better code.
| < Day Day Up > |
|