Chapter 3. Ensuring Quality

All the best practices, fancy algorithms, and patterns in the world mean nothing if the code doesn’t work properly. We all want to build the best app possible and minimize bugs. The themes of this chapter revolve around maintainability, error prevention, and writing correct code.

When working on a team, other developers must work with the code you write. They add new features and fix bugs. If you write code that’s easy to read, it will be more maintainable—that is, other developers will be able to read and understand it. Even if you’re the sole developer, coming back to code you’ve written in the past can be a new experience. Increased maintainability leads to fewer new bugs being introduced and quicker task turnaround. Fewer bugs mean fewer software life-cycle costs and more time for other value-added features. It is this spirit of maintainability that motivates the content in this chapter.

Similar to maintainability, error prevention is an important quality concept. Users can and will use apps in a way that finds the one bug that we never thought would happen. Recipes 3.1 and 3.4 give essential tools to help. Proper exception handling is an important skill and you’ll learn that too.

Another feature of quality is to ensure the code is correct, and unit testing is an essential practice. Although unit testing has been with us for a long time, it isn’t a solved problem. A lot of developers still don’t write unit tests. However, it’s such an important ...

Get C# Cookbook 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.