Studying HtDP

October 19, 2008 - 2 minute read -
functional programming HTDP

I haven't posted in a while, but I've recently been studying How to Design Programs (HtDP). It's really a book about teaching beginners how to program by following a series of recipes that tell you how to identify and solve different classes of problems. The techniques are taught in a very basic subset of Scheme. (There are actually multiple learning languages that slowly build up the available functionality.) You don't have to know any Scheme to get started though.

Basic Scheme

I'm sure you can figure out what the following does without knowing any scheme:
(+ 1 3)
(* 10 10)

They explain a bit about equality and conditionals:

(= 1 1)            ; true
(and true true)  ; true
(or true false)   ; false
(and (>= 1 1) (= 2 2)) ; true

Then building on basic arithmetic and boolean logic, they add a bit of algebra to teach how to define your own methods:

(define (add1 n)
    (+ n 1))
(define (sqr n)
    (* n n))</p>
<p>;; Tests
(= (add1 2) 3)
(= (sqr 10) 100)

It grows from those simple constructs into how to build structured and list data and how to process those kinds of data.

Why Might You Care?

It's very hard for me to judge what it would be like to learn to program using this book. I personally have 10 years of programming experience myself and learned first with BASIC, then really with Pascal and C/C++. Professionally I first programmed in Java, then C#. From there I really got interested in dynamic languages like Python then Ruby and looked a bit at Objective-C in there. By and large these are all Imperative Programming Languages. I'm sure my experience isn't unique for those of us who didn't go to MIT. So, if like me, you are new to Functional Programming then it is an interesting book because it teaches you how to think in terms of functional decomposition.

Multi-core processing is the future and functional programming, due to the ability to much more easily create side-effect free programs, is well suited for parallelization. Understanding functional programming is going to be very important for programmers in the future. We might never go to all functional programming, but we might go to more mixed-mode languages that allow us to easily write parallelized code for portions of a program that need it.