Coursera: Functional Programming Principles in Scala by Martin Odersky

It’s almost half year when I found a link on Twitter when someone pointed out to new course of functional programming in Scala. The course prepared Martin Odersky who also recorded all video materials. All enthusiastic programmers know that Odersky is author of Scala programming language. I’ve studied hard so after couple weeks I obtained a certificate. I have to note that it was my first meet with coursera itself and it left as best impressions as it could. But lets start from the beginning.

The course took 7 weeks. There was also first, zero, week which supposed to define targets, make people to understand topics etc. Everyone could also follow steps how to setup scala environment from the scratch along with Eclipse and SBT. SBT build system was new for me and I already put it into my notes as thing I need to study later. Contrary to course recommendations I used IntelliJ Idea all the time and I’ve not met any problem. It was just about the first setup of your environment but nothing new for me as I already made few REST services in scala using Spray. But back to the course itself.

Martin Odersky published couple of videos every week. The total length was about 1 hour (per a week) so nothing which would consume some significant part of your time. I’ve already have couple real experiences, some books too, with Scala so first weeks was crucial for me. As the name of course indicates, it’s not only about scala itself but about functional programming. This was the point of first weeks. I finally found out basic terms, designs and flows how modern functional programming works. Well, everyone attended some course regarding functional programming at a college but this was really good.

The work of every week was covered by one or more exercises. Despite my original feeling I have to say that those exercise were brilliant and seems for me that it was the crucial part of overall understanding. My original feeling was much more worse that today – three months after the end of course. Why? It seemed for me as little bit academical. What’s going on?

Odersky and his team prepared skeleton in scala, provide couple tests in the solution and lead you to provide the rest of missing programming code. The solution was compilable all the time but those tests where failing. You supposed to read the tutorial for an assignment and put missing code in there. The difficulty was changing in the time, especially assignment at the end of the whole course was little bit hard but everyone will understand working with collections or stream approach in scala to death 🙂

The problem I pointed out few lines above is that I spent a lot of time with reading and undestanding of the problem itself, e.g. how works very popular game of infection, or how they design the skeleton, e.g. words decomposition in the assignment of anagrams.

Once you was satisfied with your solution you just use git with SBT’s commit and send your solution to repository. I’ve already written that original solution already contained few tests. The lecturer developed more non-public test used to testing when someone committed his solution. This sometimes arouse passion because you have developed your solution, your tests works so you decided to commit it to coursera’s repository. After couple minutes when their tests were done you found out that your solution is not working for large data. What to do now? You do not have that test, you even do not have attributes of large test. One can just look into his code and try to find problem without any real point where to start.

The last thing was the only issue on perfect course in all other respects. There was also a follow-up in the form of course about Reactive Programming. Thing went around Akka, async/await, Futures and promises and so on.

I really enjoyed the course. After few moths I have to say that it’s much more efficient than any kind of reading – obviously because of assignments. It turns out into my almost primary target where to learn new things as there is multiple things to learn.

Scala: get rid of not-null validations

Scala has been always known as a language which allows special handling of null values. There is ton of articles regarding Some[T], None, Option[T].

What is most annoying code for me? Null validations, see usual example:

class Entity {


class ServiceA {
def method(a: Entity, b: Entity, c: Entity, d: Entity) = {

class ServiceB(val a: ServiceA) {
def method() = {

When you start to write save code in the term of fails-as-fast-as-possible, your code, services or even domain model, will be weedy, you will find such boilerplate code at every method because you can’t be sure which parameter supplied someone to you class or method.

Unfortunately Scala has beautiful way how to achieve nice and simple code – without these checks. If you don’t think that null is proper state for your class, just dismiss this option. How to do that?

class Entity extends NotNull{


Well, that’s all. Look at screenshot from my IDE what is about to happen:

notNull trait scala

Now, if you are sure that you don’t want to allow null value for your entity, you can implement NotNull trait and you can remove many lines from your source code.

I was surprised when I found this trait in scala code, because many tutorials or even famous Scala for the Impatient book does not mention this simple but beautiful piece of code.