I was just thinking about teaching methods in programming books. Why do so many of them use this method: “You might try to code it with method X, but that would be silly. A better method would be method Y because of blah blah. But that wouldn’t really work. The simplest way to do it would be this single line, method Z.” Why didn’t they just get to the point in the first place? Or sometimes, they’ll go through the history of how something was done in a language as it changed over time. Irrelevant! The absolute best way to teach something in code is to give an example. Three pages of confusing computer science language can be summarized in a small bit of code example. If you care to see an example of this, look at the bit of pseudocode on this page that easily summarizes the main point of the previous three sections.
method1 {
try {
call method2;
} catch (exception e) {
doErrorProcessing;
}
}
method2 throws exception {
call method3;
}
method3 throws exception {
call readFile;
}