ABSTRACT

It should go without saying that we want our programs to be correct. That is,we want our algorithms to produce the correct output for every possible input, and we want our implementations to be faithful to the design of our algorithms. Unfortunately however, in practice, perfectly correct programs are virtually nonexistent. Due to their complexity, virtually every significant piece of software has errors, or “bugs” in it. But there are techniques that we can use to increase the likelihood that our functions and programs are correct. First, we can make sure that we thoroughly understand the problem we are trying to solve and spend quality time designing a solution, well before we start typing any code. Second, we can think carefully about the requirements on our inputs and function parameters, and enforce these requirements to head off problems down the road. And third, we can adopt a thorough testing strategy to make sure that our programs work correctly. In this chapter, we will introduce the basics of these three practices, and encourage you to follow them hereafter. Following these more methodical practices can actually save time in the long run by preventing errors and more easily discovering those that do creep into your programs.