Chapter 04

Writing, Debugging, and Testing Functions

This chapter is about writing functions to reuse code, debugging logic errors during development, logging exceptions during runtime, and unit testing your code to remove bugs and ensure stability and reliability.

This chapter covers the following topics:

  • Writing functions
  • Debugging during development
  • Logging during runtime
  • Unit testing

Writing functions

A fundamental principle of programming is Don't Repeat Yourself (DRY).

While programming, if you find yourself writing the same statements over and over again, then turn those statements into a function. Functions are like tiny programs that complete one small task. For example, you might write a function to calculate sales tax and then reuse ...

Get C# 8.0 and .NET Core 3.0 - Modern Cross-Platform Development - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.