Mechanical

How Not to Teach Programming

Note: heavy use of HTML unicode character codes here. If some of the following is garbled, I trust you'll understand.

So I have the book Programming in Haskell. So far the book seems to be fairly straightforward, except for one little hitch. Here's the start of the second paragraph of the inside front cover:

This introduction is ideal for beginners: it requires no previous programming experience and all concepts are explained from first principles with the aid of carefully chosen examples. Each chapter contains a series of exercises ...

Exercises? For beginners? Well, do beginners to programming want to read about programming or to program? Almost everyone I've ever met wants to dive in and make things which print "Hello, World" and move on from there. We want to program, so a Haskell book for beginners with exercises sounds perfect for me.

So since this is for beginners, some might be surprised to see this:

  (⨁)  = λx → (λyxy)
  (x⨁) = λyxy
  (⨁y) = λxxy

But the text builds up to this at that point and the above is understandable (the author's really good about this), but still, it's the sort of thing which makes many a student put down a book. However, that was merely a formalized definition of something and wasn't too bad. Here's what's too bad:

  > [ x ↑ 2 | x ← [1..5]]

The above is a list comprehension in Haskell. It will generate a list of the square of the numbers one through five. Note that this is not the mathematical notation of a comprehension. Prior to the above horror, the author clearly gives the mathematical notation:

  { x² | x ∈ {1..5} }

So the author can't use the excuse that he was showing mathematical notation. However, the keen observer might notice a small difference between them:

  > [ x ↑ 2 | x ← [1..5]]
  { x² | x ∈ {1..5} }

Hmm, what's that leading angle bracket on the Haskell version?

THIS WAS MEANT TO BE TYPED AT A HASKELL PROMPT!!!

Yes, that's right. Here's that full snippet from the book:

  > [ x ↑ 2 | x ← [1..5]]
  [1,4,9,16,25]

The author gives code that the beginning student cannot type in! There is a "symbol table" in Appendix B which has a mapping of those funky characters to what the poor student should type in, but it's not even mentioned at the beginning. New to programming? You get to guess this. I'm not making this up. Even the book's intro to the Hugs compiler has this:

  > 2 ↑ 3
  8

What on earth could convince someone writing a programming book for beginning programmers that having them type in examples they can't type in would be a good idea? The rest of the book seems fine, but this is just, wow. I'm at a loss for words. And I just gave you the easy ones to figure out. You think the beginner is going to know to type \ for λ or /= for ?

Tags:
As someone who learned how to code in BASIC, then stopped there...all those example lines confuse me to no end. ;_;
Wow, that's awful. I guess Haskell will continue to be an inappropriate starting language...
Actually, I think Haskell could be a great starting language -- if Haskell programmers would focus on what people really do with computers and programs. In this case, it's just a book that's has a glaring weakness in it.

Edited at 2009-02-17 04:02 pm (UTC)
Oh, I'm willing to concede that (having never actually done anything with Haskell, I'll take your word for it). But until there is a good book on the subject, it's going to remain a theoretically great starting language.

Edited at 2009-02-17 04:25 pm (UTC)
I'll have a go at defending this:

It's showing the student what they should expect to see. I'll bet that bit was in a monospaced font, perhaps with a different background colour? Here's the alternative phrase:

"Type [ x ↑ 2 | x ← [1..5]] into the Hugs prompt. You should see: [1,4,9,16,25]"

It's more verbose, and less clear, once you know what's going on. I'll concede the point that the book needs to make it clear that examples include the hugs prompt. I don't have the book so I can't check this myself. But it's far from an uncommon thing to do.

The python interpreter looks like this: >>> Any beginner's python book will contain lots of examples copied-and-pasted from that:

>>> [x**2 for x in range(1, 6)]
[1, 4, 9, 16, 25]


Of course, if the book is any good, it will start by telling you to start the python interpreter and seeing what it looks like. It should be clear, even to a complete beginner.

Another example: people writing about unix shells will often display the prompt in their examples. People writing about the DOS prompt might do the same. Heck, I remember program listings from computer magazines back in the OLD days. Every line of the listing started with a line number, but you knew you weren't supposed to type those in; the basic shell would provide them for you.

So while it's bad if the book doesn't make any connection between the > and the hugs prompt, I don't think it's an error to show the prompt. It provides an important check for the reader: what they see on their screen should exactly match what the book shows.
It's not the prompt which is bad. It's the symbols you can't type. This is a book which claims to be useful to people who've no prior programming experience. Giving them stuff to type which they can't type is awful.

It's also a 2007 book -- relatively new, and some of the examples are either wrong or confusing. So far I'm not impressed.
Oops; I saw the arrow symbols and thought "Hmm", but then I completely misinterpreted your point and forgot about that.
(I thought you meant: "There is a prompt in the example, therefore the student will think they should type the prompt, which won't work")

Oh well. Yeah, that's pretty dumb. I learnt a bit of haskell at uni; we met list comprehensions as: "you type 'x <- [1..5]'; remember it because <- looks a bit like an epsilon, or a bit like a left arrow".
While I agree, { x² | x ∈ {1..5} } is notation for set comprehension, not list comprehension and is presented as an analogy, since the students can be assumed to be already familiar with it.

The notation he gives is the correct mathematical notation for list comprehension if the lists are denoted by brackets. (Angled brackets are used more often, and at any rate the same kind of brackets should be used in both places.)
This just amazes me. The prompt thing, I can see; it can be really difficult remembering what it is that you didn't know when you were a wee little lad.
...but the fancy characters? What the bleep were they thinking? I can't see how it's easier to have them, nor how they'd think it would improve the book to have them.