"Functional Programming Principles in Scala" online Coursera course
This spring I have taken a “Functional Programming Principles in Scala” online course, taught by professor Martin Odersky from École Polytechnique Fédérale de Lausanne (Course website).
It is intented to teach about functional programming and Scala totally from scratch, however some programming experience is required (Java/C# is recommended, C/C++/Python/Javascript/Ruby is sufficient). The course duration is 7 weeks with 5-10 hours of workload each week, however I averaged at about 4 hours.
Course Syllabus
- Week 1: Functions and Evaluations - overview of functional programming, scala
- Week 2: Higher Order Functions - recursion, currying, using functions as values
- Week 3: Data and Abstraction - classes, immutable objects, polymorphism
- Week 4: Types and Pattern Matching - pattern matching, types, subtypes and generics
- Week 5: Lists - working with lists, list reduction
- Week 6: Collections - maps, for translations, search
- Week 7: Lazy Evaluation - streams, lazy evaluation, infinite sequences
Assignments
In total there were 6 assignments with 1 week for catching up. Each week a new assignment would be published along with handout archive file and a description of problems.
Assigment files would contain thoroughly commented (with hints on how to continue) code structure with key pieces missing, the task usually was to “fill in the gaps”. A small (and usually incomplete) test suite was included, however students were encouraged to write their own more thorough tests.
Running the application, tests, style checks and submitting finished assignments were all done with sbt. Upon submission assignments were automatically graded (usually within 10 minutes of submission).
- Week 1: Recursion
- Week 2: Functional Sets
- Week 3: Object-Oriented Sets
- Week 4: Huffman Coding
- Week 5: no exercise this week, only videos
- Week 6: Anagrams
- Week 7: Bloxorz
Impressions
I enjoyed this course very much. At first I found it difficult to come up with recursive solutions, but within few weeks that got much easier.
From the first week I was impressed how small functions were - usually less than 10 lines and probably none more than 15-20 lines of code.
I’ve had quite a few AHA! moments when prof. Odersky described some Scala features. For example pattern matching just blew me away. I remember myself seeing a similar example, thinking “Holy ^$@%!” and not being able to sit down after so much excitement.
trait Expr
case class Number(n: Int) extends Expr
case class Sum(e1: Expr, e2: Expr) extends Expr
def eval(e: Expr): Int = e match {
case Number(n) => n
case Sum(e1, e2) => eval(e1) + eval(e2)
}
Or that for
expressions can be expressed in terms of map
, flatMap
and
filter
. Or how awesome Streams are.
Another thing that I found interesting is the last assignment. The last assignment was a solver for a game called Bloxorz. Sure, it’s a simplified version of it (no orange tiles, circles or crosses), but fun nonetheless. It involved using streams to solve it.
However, I have only one tiny problem with the course. That is I didn’t learn how to write Scala programs from scratch on my own. Having to write assignment programs from scratch would’ve been useful, but also (most likely) very difficult. A minor problem, that I managed to fix within few hours with online resources.
Last thoughts
Did I find it useful? Yes I did. Functional programming requires a different way of thinking and I can already see that it made an impact in how I write programs. And I find programming Scala very enjoyable.
Would I recommend this course to you? Oh yes, definitely. It is an easy way to get familiar with functional programming and requires little time. In fact I myself have registered after reading many positive comments on Hacker News.
If you want to take a look at it yourself, here’s the course website: Functional Programming Principles in Scala
To learn more Scala I’m using it to solve Matasano Crypto Challenges, so if you’re interested in (learning) cryptography, check them out as well!
Subscribe via RSS