CSC302 2007S, Class 04: Goto Considered Harmful Admin: * Thursday at noon: Summer research opportunities. * Questions on HW2? * Friday's reading is the same as Wednesday's, so no readings distributed today. Overview: * Context. * Dijkstra's Famous Letter. * Permutation with Repetitions. /Context/ * The Story of Mel, A Real Programmer * Mel was programming in hexadecimal, rather than a "real" programming language * Why? * Macho * Awesome hack: Integer rollover exits loop * Wanted to control details that a higher-level language would make it impossible to control * Where instructions were on the memory drum * Permits instructions to be used as instructions AND as data * Could produce more efficient code - optimized so that seek is not costly * Also pessimized * The problem? * Really hard to tell what the code does * Really hard to change * The context of GTSCH * Current growth in "high level" languages * But goto is "low level" * So why was it in high-level languages? * The focus was less on control and more on other issues * Data representation * Location of data and program in memory * Temporaries and order-of-operations in arithmetic expressions * Control structures were "discovered"/"invented" * But goto remained * Go to identified as a problem by various programmers * Go-to ridden code is hard to read/understand and modify/fix * Dijsktra served as "spokesperson" for a wide variety of computer scientists /Go To Statement Considered Harmful/ * Published in 1968 in "Communications of the ACM" * A "letter to the editor" * Thesis * Programs with goto have difficult-to-understand dynamics * "The unbridled use of the go to statement has an immediate consequence that it becoms terribly hard to find a meanigful set of corrdinates in which to describe the process progress." * "The go to statement should be abolished from all "higher level" programming languages"j * Argumentation strategy: Figuring out the sequence of textual/dynamic indices is harder in goto-laden programs * Also: You can do everthing that goto can without goto. * Why is the sequence of textual/dynamic indices is harder in goto-laden programs so important? * To understand the value of a variable, you need to know where you are in the program (example of "number of people in the room") * Can help the reader, as he/she tries to "hand execute" the program Counter-arguments? * There are ways to use "goto" correctly * E.g., to make it more like the while loop * Don't always want to enter a while loop at the top * Sometimes want early exit from loops * Do you trust the programmer? Permutation with Repetitions on Wednesday