[racket] HtDP for programmers?

254 views
Skip to first unread message

mi...@goblin.punk.net

unread,
Jun 27, 2012, 1:39:04 AM6/27/12
to Racket mailing list
I am planning to work through _How to Design Programs_ but
already have some (imperative) programming experience as well as
some exposure to Racket/Scheme.

I found the following piece of advice in the mailing list
archive. Any updates or other tips?

http://groups.google.com/group/plt-scheme/msg/167c9643e187d265

Thank you,
Mike
____________________
Racket Users list:
http://lists.racket-lang.org/users

Stephen Bloch

unread,
Jun 27, 2012, 2:43:57 AM6/27/12
to mi...@goblin.punk.net, Racket mailing list

On Jun 27, 2012, at 6:39 AM, mi...@goblin.punk.net wrote:

I am planning to work through _How to Design Programs_ but
already have some (imperative) programming experience as well as
some exposure to Racket/Scheme.

I found the following piece of advice in the mailing list
archive.  Any updates or other tips?

http://groups.google.com/group/plt-scheme/msg/167c9643e187d265

That piece of advice ends with "avoid draw.ss exercises and use world.ss instead.  However, this is a nontrivial shift."  If you're using _How to Design Programs, 2nd edition_, this shift is already made for you.

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.  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.  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.  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.

The design recipe is key.  When Matthias first showed it to me in 1999, I thought "this is too dumb for words," but it's really incredibly helpful.  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.  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.

I was at a CS pedagogy conference last year and mentioned this test-driven design technique to my roommate, a colleague from another school.  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."  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."  I might have added "freshmen -- and people who already know imperative programming" :-)

Stephen Bloch



Matthias Felleisen

unread,
Jun 27, 2012, 10:08:29 AM6/27/12
to mi...@goblin.punk.net, Racket mailing list
The advice is appropriate for someone who has a good
amount of programming experience and is comfortable
with some Racket.

Today I would amend it with a pointer to the second
edition of the book (work in progress):

http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html

(see note on Draft version on first page).

Again, holler if you need help -- Matthias

saad bashir

unread,
Jun 27, 2012, 2:38:54 PM6/27/12
to Matthias Felleisen, Racket mailing list
I am a novice programmer learning it primarily through How to Design Programmes, 2nd edition.  I have to say it is a unique book, as it claims and superbly designed and written.  I think any one who wants to learn programming should go through the entire book - if he/she knows it, the progress will be very quick and the result from the basics to the advanced levels will be logical and lay a foundation for a lifetime.

Saad

Harry Spier

unread,
Jun 28, 2012, 9:28:59 AM6/28/12
to mi...@goblin.punk.net, us...@racket-lang.org
As an imperative programmer learning Racket I found HtDP 2nd edition immensely useful.  I also used "The Little Schemer" to learn the recursive way of doing things and functions as first class values (i.e. passing functions as parameters to other functions).  And then sytematically going through The Racket Guide .
 
Harry Spier
Reply all
Reply to author
Forward
0 new messages