Cause and Discovery of the Bugs
This lesson explores the causes of bugs and then explains how to discover the bugs.
We'll cover the following
As commonly known, any device that runs some piece of computer program contains software bugs. Software bugs plague computer devices from the simplest to the most complex. Debugging and fixing software bugs is among the less favorable daily activities of a programmer.
Causes of bugs #
There are many reasons why software bugs occur. The following is an incomplete list, roughly from the design stage of a program through the actual coding of it:
-
The requirements and specifications of the program may not be clear. What the program should actually do may not be known at the design stage.
-
The programmer may misunderstand some of the requirements of the program.
-
The programming language may not be expressive enough. Considering that even the native speakers of human languages may get confused by language grammar, the unnatural syntax and rules of programming languages may be the cause of mistakes among programmers.
-
Certain assumptions of the programmer may be incorrect. For example, the programmer may be assuming that 3.14 would be precise enough to represent π.
-
The programmer may have incorrect information on a topic or none at all. For example, the programmer may not know that using a floating-point variable in a particular logical expression would not be reliable.
-
The program may encounter an unforeseen situation. For example, one of the files of a directory may be deleted or renamed while the program is using the files of that directory in a foreach loop.
-
The programmer may make silly mistakes. For example, the name of a variable may be mistyped and accidentally matched the name of another variable.
Unfortunately, there is still no software development methodology that ensures that a program will always work correctly. This is still a hot software engineering topic where promising solutions emerge every decade or so.
Discovering the bugs #
Software bugs are discovered at various stages of the program’s lifetime by various types of tools and people. The following is a partial list of when a bug may be discovered, from the earliest to the latest:
- When writing the program
- By the programmer
- By another programmer during pair programming
- By the compiler through compiler messages
- By unit tests as a part of building the program
- When reviewing the code
- By tools that analyze the code at compile time
- By other programmers during code reviews
- When running the program
- By tools that analyze the execution of the program at run time (e.g. by valgrind)
- During QA testing, either by the failure of assert checks or by the observed behavior of the program
- By the beta users before the release of the program
- By the end users after the release of the program
Detecting bugs as early as possible reduces the loss of money, time and in some cases human lives. Additionally, identifying the causes of bugs that have been discovered by the end-users is harder than identifying the causes of bugs that are discovered early during development.
The next lesson will explain how unit testing can be used for catching bugs.
Get hands-on with 1400+ tech skills courses.