Functional programming in Scala
Posted on 2016-06-21 Edit on GitHub
I recently signed up for the Functional Programming Principles in Scala specialization on Coursera. Learning from Martin Odersky, an expert in the field of functional programming (and the creator of Scala), is too good an opportunity to pass up. Though I'm quite busy at the moment, good courses like this are usually only held once a year, so if I don't take it now, I'd have to wait until next year.
I've never used Scala, but I'm familiar with Java and Clojure, so neither the syntax nor the functional programming concepts are completely new to me. Furthermore, much of the course material and exercises are based on SICP, which I've been trying to work through for a while now, so I've something of a head start when it comes to the weekly assignments.
The Scala language seems big–which may not make it the best choice for a course that's also trying to teach lots of new concepts; it does, however, mean that tooling like IntelliJ support and unit test frameworks are readily available, which is great.
Having just started using Scala, I'm not in a position to judge it beyond superficial issues like syntax, which is what I'll cover here.
My initial impression of the syntax is so-so–Martin calls Scala's syntax "light-weight", which it definitely isn't, while JVM expert Cliff Click calls Scala "the C++ to Java's C", which is really not fair–Scala does not try to maintain backward-compatibility with Java the way C++ tries to do with C, allowing its syntax to be much saner.
What learning Scala has really impressed upon me is the beauty of Lisp's syntactic regularity–with symbolic expressions, we don't have to worry about issues like order of operations or how to arrange keywords. Some of Clojure's macros, like ns
, introduce significant mental overhead, but I'd still take parens over braces any day of the week.
Scala is an older language than Clojure–first released in 2004, a few years before Clojure's 2007 debut. In that sense, it led the way for Clojure as a functional language on the JVM, and no doubt Clojure has benefited from the many lessons learned in the Scala community.
What I'll try to do for this course is to implement exercise solutions in both Scala and Clojure–not only would I learn more Clojure, but I'd also approach the problem in a different way, which is always good for reinforcing learning. Since many of the problems are out of SICP (which uses Scheme), I'll even have a reference for my Clojure solutions. Hopefully I'll kill several birds with one stone with this approach!