For example, the following code sample in C (intended to find and copy a series of digits from a larger string) has several problems:
First of all, it doesn't give the right answer. With the given starting string, it produces the output "13", when the correct answer is "123". A programmer who does not recognize the structural problems may seize on one statement, saying "ah, there's an extra increment". The line "++i" is removed; but testing the code results in an infinite loop. "Oops, wrong increment." The former statement is added back, and the line above it is changed to remove the post-increment of variable i:
Testing the code now produces the correct answer, "123". The programmer sighs in contentment: "There, that did it. All finished now." Additional testing with various other input strings bears out this conclusion.
Of course, other problems remain. Because the programmer does not take the trouble to fully understand the code, they go unrecognized:
While the solution is correct for a limited set of input strings, it is not fully correct, and since the programmer did not bother to understand the code, the errors will not be discovered until a later testing stage, if at all.
Also known as "Trial and Error", "Generate and Test", "Poke and Hope",1 "The Birdshot Method" and the "Million Monkeys Programming Style".
Catania, Anthony (1987). ""ever, although there are some algebraic skills, topics on factorization, rational."". Mathematics and Computer Education. 21. University of Michigan: 74. /wiki/Mathematics_and_Computer_Education ↩