A couple of weeks ago I visited Northeastern and Harvard where I gave guest lectures on the subject of programming effectively in ML. In both cases, I was talking to a class full of undergraduates who had been studying ML for the semester. It was great fun, and in the Harvard case, the lecture was taped, so I hope to eventually be able to post a link to it here.

The lecture I gave was in part inspired by a book I read years ago called Effective Java, by Josh Bloch. I picked up the book when I first came to Jane Street when I was looking for something I could recomment to the people who were thinking about how to build trading apps using C# and Java. Effective Java is organized as a series of short lessons (or "items", in the terminology of the book), well chosen, well described, and with clear examples.

It's not hard to see why a functional programmer would like Bloch's book. Consider the following items:

  • Item 15: Minimize mutability
  • Item 16: Favor composition over inheritance
  • Item 22: Use function objects to represent strategies

These are all messages that come naturally to a functional programmer.

The lecture I gave was organized around a set of small lessons of similar scope that I've learned about programming in ML over the years. Here's the list of bullets I used:

  • Favor readers over writers
  • Create uniform interfaces
  • Make illegal states unrepresentable
  • Code for exhaustiveness
  • Open few modules
  • Make common errors obvious
  • Avoid boilerplate
  • Avoid complex type-hackery
  • Don't be puritanical about purity

A lot of these are ideas that I've talked about in previous posts, and some of them are obvious to any experienced ML programmer from the heading alone. A few are perhaps worth more elaboration, and I hope to discuss some of them in later blog posts.

In the meantime, I'd be interested in hearing suggestions for other items to add to the list.