Repository navigation
Expand file tree
/
Copy pathProgramDefects.txt
More file actions
15 lines (11 loc) · 3.86 KB
/
Copy pathProgramDefects.txt
File metadata and controls
15 lines (11 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Program Defects
This text is about program errors or defects and how to avoid them. It does not matter much whether a program runs efficiently if it does not do what it is supposed to do. Very often, defects appear in a software product after it is delivered, sometimes with disastrous results. Some notable software defects have caused power brownouts, telephone network saturation, space flight delays, loss of spacecraft, and even loss of life.
One way to show that a program is correct is by thorough testing, but it is difficult to determine how much testing needs to be done. In fact, testing can never demonstrate the complete absence of defects. Furthermore, in some situations it is very difficult to test a software product completely in the environment in which it is used, such as software that controls a missile or prevents a meltdown in a nuclear power plant. You may also hear the term bug used to refer to a software defect. Debugging is a commonly used term for removing defects, and a debugger is a commonly used testing tool that helps find defects. Because of societyÕs ever-increasing dependence on computer systems, however, many software professionals have come to believe that calling software defects bugs tends to trivialize their serious consequences.
Careful design and careful testing can reduce program defects. Obviously, it is much easier to eliminate defects by design rather than by removing them later through testing.
There are three kinds of defects or errors that you might encounter
Syntax errors
Run-time errors or exceptions
Logic errors
Logic Errors
Logic errors are the final category of error. A logic error occurs when the programmer/analyst has made a mistake in the design of a class or a class function or has implemented an algorithm incorrectly. In either case, even if the C++ code compiles and runs, it will not meet the specification for that functionÑthat is, it will produce incorrect results. If the user is fortunate, a logic error may cause a run-time error in another function that relies on the results generated by the faulty function, but this may not happen. Most logic errors do not cause syntax or run-time errors and, consequently, are difficult to find. Some examples are given in the Pitfalls in this chapter. Sometimes logic errors are found during testing by careful comparison of the actual program output with the expected results. This can happen only if the tester provides test cases that cause execution of the incorrect portion of the algorithm. Also, the tester must determine beforehand the output that should be generated, so that the expected output can be compared with the actual output.
A worse scenario is when logic errors are encountered during real-world operation of a program. There are many examples in which logic errors have made the popular news. The original Mars Lander spacecraft crashed because of inconsistent calculations (feet versus meters). Billing programs have sent out bills for exorbitant amounts of money. Logic errors in automatic teller machine (ATM) programs or off-track betting programs have caused machine owners to lose significant amounts of money. Many popular operating systems have been released with logic errors that have enabled hackers to access computers easily. One popular word processor, when integrated with any document management system, frequently would ÒeatÓ the document off the server and leave an empty file in its place. In the 1980s several patients died after errors in the software that controlled therapeutic radiation machines gave them massive overdoses. In August 2004, two of the four automobile recalls listed in Consumer Reports were due to software errors: an automatic braking system and an ignition control system. Both errors could lead to fatal accidents. To avoid these kinds of catastrophes, software professionals must be very diligent about detecting and correcting logic errors.