<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 27, 2012, at 6:39 AM, <a href="mailto:mike@goblin.punk.net">mike@goblin.punk.net</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>I am planning to work through _How to Design Programs_ but<br>already have some (imperative) programming experience as well as<br>some exposure to Racket/Scheme. <br><br>I found the following piece of advice in the mailing list<br>archive. &nbsp;Any updates or other tips? <br><br><a href="http://groups.google.com/group/plt-scheme/msg/167c9643e187d265">http://groups.google.com/group/plt-scheme/msg/167c9643e187d265</a><br></div></blockquote><br></div><div>That piece of advice ends with "avoid draw.ss exercises and use world.ss instead. &nbsp;However, this is a nontrivial shift." &nbsp;If you're using _How to Design Programs, 2nd edition_, this shift is already made for you.</div><div><br></div><div>I've taught functional programming in Racket/Scheme to a number of students who already had imperative programming experience, and they often make problems much harder and more complicated than they need to be. &nbsp;For example, when asked to do something to each of the items in a list, they'll find the length of the list, initialize a numeric variable to 0, initialize another variable to a "default" result, then try to loop over the list, doing a "list-ref" and modifying both of these variables each time. &nbsp;You can do that, but it's not idiomatic functional-programming style, and the resulting code is about three times as long and substantially slower than if you did it in a more functional style. &nbsp;Which is why the beginning and intermediate student languages in DrRacket don't ALLOW you to modify an already-defined variable: sure, a professional programmer will occasionally need to do this, but you'd be amazed at how much sophisticated programming you can do without assignment statements.</div><div><br></div><div>The design recipe is key. &nbsp;When Matthias first showed it to me in 1999, I thought "this is too dumb for words," but it's really incredibly helpful. &nbsp;Especially the part about writing test cases before you start writing the code: whenever you find yourself falling into an imperative morass like that in the previous paragraph, just stop and write down several examples of calling the function, together with their correct answers. &nbsp;This enables you to focus on the relationship between arguments and results, rather than on a particular imperative algorithm for getting from the former to the latter, and you may well find that with this revised focus, the "algorithm" becomes almost trivial.</div><div><br></div><div>I was at a CS pedagogy conference last year and mentioned this test-driven design technique to my roommate, a colleague from another school. &nbsp;My colleague said "Well, that's great for a software engineering course, but these are freshmen; they're not ready for test-driven design yet." &nbsp;I replied "No, you've got it backwards: the students in your software engineering course MIGHT be sharp enough and experienced enough to sometimes do without test-driven design; the freshmen are the ones who need it the most." &nbsp;I might have added "freshmen -- and people who already know imperative programming" :-)</div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div>Stephen Bloch</div><div><a href="mailto:sbloch@adelphi.edu">sbloch@adelphi.edu</a></div><div><br></div></span><br class="Apple-interchange-newline">
</div>
<br></body></html>