Defensive Coding Techniques
Code is almost organic and evolves over its lifetime as new features are added, fixes are implemented, and refactorings occur at regular intervals. As code changes and developers enter and leave the project, there’s a chance that some of these changes may introduce bugs.
In Part 2 of this book, we discussed testing strategies for detecting these bugs before they reach production. In this chapter, we’ll talk about a few additional techniques that help developers catch and resolve bugs during development. Along the way, we’ll also explore a few newer features in C# and their roles in keeping your code stable and healthy.
We’ll cover the following topics in this chapter:
- Validating inputs
- Protecting against null
- Moving beyond classes
- Advanced type usage