Computer programs often contain errors. They are nicknamed bugs because many years ago, a moth flew into computer pioneer Grace Hooper’s hardware and her program produced an incorrect result. Insects aside, why do software bugs happen? It’s because computer programming is only as good as the logic a programmer envisions in his mind.
Let’s take an example. This is fictitious and is only used to illustrate a point:
- Let’s say you’re a programmer, and I am the customer.
- I ask you to write a program that tells me if a number is positive or negative.
- So you write some code that looks like:
if x > 0
then print (“The number is positive.”);
else print (“The number is negative.”); - You test the program using some numbers like -1 and 1 and get the correct results. You are happy. You release the program.
- Lots of people use your program, and everyone is getting correct results. Everyone is happy.
- Along comes a user who tries the number 0 and gets “The number is negative.” as a result….