Saturday, February 15, 2014

Learning Scala on Coursera

I’ve taken the following online course on Coursera.

In this course, Prof. Martin Odersky, the creator of the Scala programming language, teaches us functional programming using Scala.

As I’m not very good at English, I was little nervous whether I would get them right. However, after I’ve finished watching the first video lecture, I found it not so hard. Students can download the slides corresponding to each video lecture, so they helped me keep track of what is going on in the lectures. Each video lecture includes some quizzes, which are effective for students to confirm each learning step. The course consists of 8 lessons divided into 10-20 minute sections.

After every lesson, students submit their solutions to the programming assignment using SBT, and then the grader, which is something like a CI server, sends back a submission score automatically. Students can keep fixing until getting a 100% score by the hard deadline. After the class ends, the students that complete the class will receive a certificate in PDF format.

Some program assignments can be challenging, so you might be stuck with them. In the honor code, no one can write up any solutions, nor can they tell people about the detail of the lessons. If you need any help, the discussion forum will help you solve problems.

Before I joined this course, I had been studying Scala by myself, searching keywords on Google, reading the texts written by early adopters, tinkering a bunch of Scala API, staring at mysterious DSL codes curiously, and so on.

After a while, I was aware of the fact that my Scala code was merely something like a better Java or a type-safe Ruby. In order to know what the FP (Functional Programming) is, I tried to learn Haskell with the book “Learn You a Haskell for Great Good”, and to read the document “All About Monads”. That helped me know benefit of functional programming, but I had not realized how to add essence of functional programming in Scala. Furthermore, I was confused why I should use Scala as a FP language because Scala doesn’t ensure referential transparency and has interoperability with Java libraries in OOP (Object-Oriented Programming).

Through the lessons, I got to know the concept of Scala as a scalable OOP + FP language. The following quote is the most impressive part for me in the book “Programming in Scala: A Comprehensive Step-by-Step Guide”, many parts of which are followed in the lessons.

Functional on the “outside”: … You saw that lists are purely functional on the "outside" but have imperative implementation using list buffers on the "inside". This is a typical strategy in Scala programming: trying to combine purity with efficiency by carefully delimiting the effects of impure operations.

If you have never carefully read this book written by Prof. Martin Odersky, you might misunderstood a lot of things. I’ve heard bad impressions about Scala several times, but in most cases I think they were completely beside the point.

  • Do you believe that imperative programing is always wrong?
  • Do you believe that functional programing is always right?

If your answer to either of the above questions is YES, please take a look at the introduction page of the Haskell official site, which says “When C is better”.

Now it looks so obvious that I no longer hesitate to use Scala. I can write more, but not too much, functional code in Scala and also improve error-prone code in imperative programming languages like Java.