Thursday, August 14, 2014

Functional Programming Principles in Scala

It was a bit of surprise to me to discover a few years ago that Functional Programming (FP) was considered to be(come) mainstream.

FP everywhere, JavaScript, Groovy, Scala and even in Java 8. Not to mention Clojure, the Lisp revival.

Not that I doubt about the benefits of FP, but simply because FP was already mainstream, at least for me, back in the days when I was a student in a French University (Paris, Jussieu), at the beginning of the eighties... Thirty years ago !

Lambda calculus, LF (langage fonctionnel), an FP language implemented on Multics, Lisp, and more precisely LeLisp by Inria, were important parts of my degree course. Recursive programming was a way of life for me and my friends ...

And then after I worked in the real world. No more recursion, no more lists, no more car/cons/append/caddr and the like. Instead Awk, Perl, C, C++, Object Oriented programming.

So when I knew more about Scala in a Paris JUG meeting in april 2010, a language mixing OO and FP, I was puzzled by its potentialities.

I read some books about it  ... but eventually came to the conclusion that Scala did not fit well with my professional context (in a few words: too far from Java, and as such, requiring a collective interest/support/commitment accompanied by a strong professional training).

At the same time, I discovered the Groovy language and found some interesting use cases in the periphery of application development (in short, I started to use Groovy everywhere I used Perl in a Java context, mainly for portable deployment or administration tasks). Groovy is by nature Java friendly (one can use it simply as a better Java) and as such its learning curve is very smooth compared to what is required to practice on a daily basis in Scala.

And I forgot Scala for some years until I started to use the Gatling stress tool, whose DSL is written in Scala. This was the first reminder. The second one was Gitbucket, also written in Scala, which I started to use as an internal Git server. The third reminder was an article of Nicolas Martignole, a well known member of the French Java community, about its transition to Scala.

Finally, the spark was a tweet of Professor Martin Odersky:

I enrolled on the Coursera site, not very sure I will be able to have enough time and energy to reach the end of the course (I remembered the feedback given about it by Nicolas Fränkel some years ago:  First, the courses are quite time-consuming!)

This was my first Mooc experience. It is a seven weeks course, requiring a personal workload of about one day per week (an average because the assignments at the end of the course require more time. Unless you use a solution available on a github repository, but you will not do that because it is nonsensical !).

On Sunday at noon (central european time), the lesson of the week is made available (a series of video and slides) accompanied by an assignment due to at least one week later (it may be more, depending on the assignment). The assignments are well documented programming exercises which can be achieved using a "Scala ready" version of Eclipse Kepler downloadable at the beginning of the course.

Each assignment can be submitted up to five times to an automatic grading system based on a series of ScalaTests, some of them are delivered with the assignment, others are only known by the Coursera grading system. The best score of each assignment is taken into account for the final grade.

There is a forum on the course site where students can help each other or be helped by the course staff.

Optionally, Coursera propose you at the beginning of the course to enroll to its  Signature Track program (I paid $US 49 for this option). The main advantage of Signature Track is to bind your identity to the work you have made during the course. At the end of the course, you obtain an official certificate (available on an permanent URL you can distribute to whoever you want) stating that you have followed the course and obtained at least 60% of the maximum score - above 80% you obtain a certificate with distinction. If you opt for Signature Track, you authenticate yourself via your webcam and a series of keystrokes (which is known to be unique to you) each time you submit an assignment.

This course is known to have good results in terms of achievement. More on this on the feedback about it given by its authors.

I can say that this experience was for me a kind of escape, very refreshing, and I was full of optimistic feelings when I sent back my last assignment...

I cannot really say that it transformed me into a Scala developer (need some daily practice on actual projects to be one of them), but at least, I think that I have the required background to enroll to the other course of EPFL on Coursera "Principles of reactive programming" when a new session will be opened.