I’m chugging along just fine in this CS51 class, but man, does Prof. Greg, not kid when he said he’ll make you feel uncomfortable by pulling out the rug. Functional Programming is very different. It’s not really hard per se, but it forces you to think in a different way than an imperative programming language does.
I spent a lot of time working back and front on the lecture slides and the official course reading (which is the official OCaml Reference) to understand this quirky language. I’ve just worked on the problem set 1 (zero-index) tasked with writing functions that work with tuples, functions, and types. It was brain melting.
And it was damn fun. Weird return types? No loops? Weird syntax that bites beginners? It’s lovable! Function currying and pattern matching is what I used most in the assignments, but I can already see the elegance of functional programming.
Because of the nature of the course, and the language in general, I cannot be objective in giving a fair estimate of my code by just checking if it works. Imagine my joy when I discovered Code Review, which was part of the Stack Exchange family. Now I’ll even have a group of people who could review my code, and see if it’s good, readable, and smooth!
Not much to show visually, but emacs has a lot going for it that makes it’s strong following understandable.
Another thing that’s trippy is the editor itself. While I’ve heard of emacs before and its reputation for having a cult-y following, this course was the perfect excuse for me to try it out. Most of the key bindings are esoteric, i.e., saving involves pressing Crtl+x Crtl+s, while copy-pasting involves Alt+w, Crtl+y, respectively.
With regards to the problem set itself, the first few ones are easy enough (relatively easy, still a bit challenging) while the latter ones involve writing functions themselves. Here’s a list of them (non-exhaustive):
- reversed – checks if an int list is in descending order.
- merged – merges an int list. (involves currying)
- unzip – unzip a list of int tuples. (okay, ‘unzip’)
- variance – checks variances within a float list.
- … and many more.
My favorite among them (the ones that made my head hurt the most) was the last two, which was writing a Run-length encoding algorithm, and a function that computes all the permutations of a list.
The course also teaches you practical programming practices! It is required to write assertions for your functions to make sure it actually works. Now it’s not just about making sure it compiles, but having a sharp eye on different test-cases!
All in all I’m really digging the course, not in the same way as 50, but in a different, much more “down the rabbit hole” way.