Additional Resources

 < Free Open Study > 

cc2e.com/1792

The following resources also address unusual control structures:

Returns

Fowler, Martin. Refactoring: Improving the Design of Existing Code. Reading, MA: Addison-Wesley, 1999. In the description of the refactoring called "Replace Nested Conditional with Guard Clauses," Fowler suggests using multiple return statements from a routine to reduce nesting in a set of if statements. Fowler argues that multiple returns are an appropriate means of achieving greater clarity, and that no harm arises from having multiple returns from a routine.

gotos

cc2e.com/1799

These articles contain the whole goto debate. It erupts from time to time in most work-places, textbooks, and magazines, but you won't hear anything that wasn't fully explored 20 years ago.

Dijkstra, Edsger. "Go To Statement Considered Harmful." Communications of the ACM 11, no. 3 (March 1968): 147 48, also available from http://www.cs.utexas.edu/users/EWD/. This is the famous letter in which Dijkstra put the match to the paper and ignited one of the longest-running controversies in software development.

Wulf, W. A. "A Case Against the GOTO." Proceedings of the 25th National ACM Conference, August 1972: 791 97. This paper was another argument against the indiscriminate use of gotos. Wulf argued that if programming languages provided adequate control structures, gotos would become largely unnecessary. Since 1972, when the paper was written, languages such as C++, Java, and Visual Basic have proven Wulf correct.

Knuth, Donald. "Structured Programming with go to Statements," 1974. In Classics in Software Engineering, edited by Edward Yourdon. Englewood Cliffs, NJ: Yourdon Press, 1979. This long paper isn't entirely about gotos, but it includes a horde of code examples that are made more efficient by eliminating gotos and another horde of code examples that are made more efficient by adding gotos.

Rubin, Frank. "'GOTO Considered Harmful' Considered Harmful." Communications of the ACM 30, no. 3 (March 1987): 195 96. In this rather hotheaded letter to the editor, Rubin asserts that goto-less programming has cost businesses "hundreds of millions of dollars." He then offers a short code fragment that uses a goto and argues that it's superior to goto-less alternatives.

The response that Rubin's letter generated was more interesting than the letter itself. For five months, Communications of the ACM (CACM) published letters that offered different versions of Rubin's original seven-line program. The letters were evenly divided between those defending gotos and those castigating them. Readers suggested roughly 17 different rewrites, and the rewritten code fully covered the spectrum of approaches to avoiding gotos. The editor of CACM noted that the letter had generated more response by far than any other issue ever considered in the pages of CACM.

For the follow-up letters, see

  • Communications of the ACM 30, no. 5 (May 1987): 351 55.

  • Communications of the ACM 30, no. 6 (June 1987): 475 78.

  • Communications of the ACM 30, no. 7 (July 1987): 632 34.

  • Communications of the ACM 30, no. 8 (August 1987): 659 62.

  • Communications of the ACM 30, no. 12 (December 1987): 997, 1085.

cc2e.com/1706

Clark, R. Lawrence, "A Linguistic Contribution of GOTO-less Programming," Datamation, December 1973. This classic paper humorously argues for replacing the "go to" statement with the "come from" statement. It was also reprinted in the April 1974 edition of Communications of the ACM.

cc2e.com/1713

Checklist: Unusual Control Structures

return

  • Does each routine use return only when necessary?

  • Do returns enhance readability?

Recursion

  • Does the recursive routine include code to stop the recursion?

  • Does the routine use a safety counter to guarantee that the routine stops?

  • Is recursion limited to one routine?

  • Is the routine's depth of recursion within the limits imposed by the size of the program's stack?

  • Is recursion the best way to implement the routine? Is it better than simple iteration?

goto

  • Are gotos used only as a last resort, and then only to make code more readable and maintainable?

  • If a goto is used for the sake of efficiency, has the gain in efficiency been measured and documented?

  • Are gotos limited to one label per routine?

  • Do all gotos go forward, not backward?

  • Are all goto labels used?


 < Free Open Study > 


Code Complete
Code Complete: A Practical Handbook of Software Construction, Second Edition
ISBN: 0735619670
EAN: 2147483647
Year: 2003
Pages: 334

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net