A Beginner's guide to the Scala Programming Language
Tags: scala, programming, beginners
Published: 2017-05-11 13:29:10

---
title: A Beginner's guide to the Scala Programming Language
published: true
description: Why scala is hard? How to learn scala in an easy way? Is learning scala worth it? 
tags: scala,programming, beginners
---

I have been dabbling with scala for some time now and most of the questions that I get from my friends/colleagues/random people is that 

- Why scala is hard?
- How to learn scala in an easy way? 
- Is learning scala worth it?

In this article I present the learning path that I took, the mistakes I made along the way and what I learnt.

I will focus mostly on a path for java developers since they are the majority, but other devs can also learn a lot from this article.

<h4>Little bit of background</h4>

The history of scala is summed up pretty well in the [scala lang wikipedia](https://en.wikipedia.org/wiki/Scala_(programming_language)) article. Main motivation behind creating scala was to create a multi paradigm programming language which is functional,object oriented which runs on the JVM. We all know that many languages now target the JVM for its performance,widespread usage etc.,

Some of the other languages targeting the JVM are [clojure](https://clojure.org/), [Ceylon lang](https://ceylon-lang.org/), [Kotlin](https://kotlinlang.org/), [Groovy](http://groovy-lang.org/), [Eta lang](http://eta-lang.org/)  etc., besides java of course. But scala is unique in its own way.

<h4>Scala as the first programming language</h4>

This mistake is often because of [buzzword first design](https://twitter.com/thepracticaldev/status/721716958769635328?lang=en) mindset. Scala is definitely not a beginner friendly language and it does not try to be. Not that it can't be, but it does not make sense to cram in so many things into a single language. The result will be a horrible mess of everything. 

Well that's not encouraging right, but don't be disheartened. Contrary to the popular myths out there, scala can be learnt with moderate effort. If you are a beginner with no programming experience then there are several MOOCs which can teach you basic programming. One of the best that I know of is [CS50](https://cs50.harvard.edu/). You can then learn little bit of python and then progress to java.

In theory any OOP language would do, such as Python/Ruby/C#.


<h4>Learn the OOP side first</h4> 

Now you are all set to take on scala. The next big mistake people would normally do is to learn the functional side of it and get overwhelmed by it. Scala is not to be blamed. We should blame what we have been taught in our undergraduate courses. Almost all of the college undergraduate curriculum do not teach foundations of functional programming. As a result our style get fixed to an imperative/OOP paradigm which is very hard to get across.

It is very much possible to do object oriented/imperative style programming in scala as well. This multi-paradigm style makes it perfect to learn functional programming without losing too much of your hair. I would highly recommend to learn the object oriented side of scala and convert small coding snippets/algorithms from java to scala.

Since scala runs on the jvm, it can very much use java libraries with very minimal changes. Try consuming java libraries in it. The interesting part is that resulting code in scala will already be more concise/shorter due to the programming syntax of scala. 

Do this step before trying core scala libraries, as they embrace functional programming more. The developers of scala didn't develop equivalent imperative/oop library equivalents of what is there in java such as spring/hibernate/gson etc., since you can use their java counterparts directly in scala. Language interoperability is a huge benefit and we must take full advantage of it rather than using core scala libraries just for the buzzword or being cool.

<h4>Getting familiar with the ecosystem</h4>

Many people underestimate this step. It is very important that you should be comfortable with the tools/ecosystem because that can frustrate you even more. Since scala works on top the jvm, the major difference from java would be the compiler obviously and then a different IDE perhaps.

Most scala programmers use [Intellij](https://www.jetbrains.com/idea/) + Scala plugin,[Eclipse](http://scala-ide.org/) as their IDEs. If you are an text editor fan there is something called [ensime](http://ensime.org/editors/) which supports major text editors.

We can use the traditional [maven](https://maven.apache.org/) build tool for projects, but it is recommended to use the [scala build tool](http://www.scala-sbt.org/) or sbt for short. Sbt offers a more simpler way to deal with dependencies and you can learn with very minimal effort to get started.

[Scastie](https://scastie.scala-lang.org/) is a handy tool to share code snippets. Kind of similar to jsfiddle.

<h4>Approaching functional programming</h4>

Since scala combines OOP and FP at a fundamental level, we can resort to lazily include FP style in our codebase. From my personal experience I would take the following route.

Java -> Scala OOP (gradual migration- since they can inter-operate)
Scala OOP -> Scala FP (can be gradual/complete refactor based on the project requirements)

IMO this what makes scala shine since at each stage of development/refactoring, it can be done part by part without breaking the regular development cycle if done properly.

![Functional programming](https://thepracticaldev.s3.amazonaws.com/i/kbfqem10vfmoj51sxtgt.jpg)

<h4>Why learn scala?</h4>

So why learn a language which is hard to learn and takes so much of your time? Many people generally tend to learn new technologies/languages for career growth/getting a break into the industry and for this scala is perfectly fine. But apart from this functional programming can genuinely make you a better programmer even if you don't use it in your day to day work. It makes you think in ways you have never thought before and the decision to use it for practical purposes lies with you since you can program in OOP style as well.

It is also preferred in,

- Machine learning (Apache spark mllib)
- Big data (Apache spark, Apache kafka)
- [Front end development](https://www.scala-js.org/)
- It also has a [native runtime](http://www.scala-native.org/) now, so you are not restricted to the JVM and can take advantage of native programming libraries. Scala native is in early stages btw.

I have written an article on [why scala will be a language that you should consider](https://madusudanan.com/blog/why-scala-will-be-the-next-big-thing/). Do give it a read.

<h4>Materials to learn scala</h4>

Unlike many other languages, scala does not have a standard learning path that fits experienced functional programmers/novices alike. I have categorized materials based on their format.

![I should learn scala](https://i.imgflip.com/1otzzy.jpg)

<cite>MOOC</cite>


- [The functional programming specialization in scala](https://www.coursera.org/specializations/scala). I wouldn't call this beginner friendly but very comprehensive nonetheless coming from the founders of scala themselves

<cite>Books</cite>

- [Scala lang books](https://www.scala-lang.org/documentation/books.html). This is pretty much the list that you want. All these books are very detailed and well crafted.

<cite>Blogs</cite>

- [The Neophyte's guide to scala](http://danielwestheide.com/scala/neophytes.html). This is easily one of my favourites on many core functional programming topics.
- [Haoyi's blog](http://www.lihaoyi.com/). Creator of scala js.
- [Blogs from scala lang authors themselves](http://www.scala-lang.org/blog/)
- [Scala tutorial series](https://madusudanan.com/tags/#Scala). I am writing a blog series aimed at learning scala in the exact same way I described above. But I am no perfect writer, YMMV. 

Difficulty in learning something is highly subjective. Some folks find math easy and some don't. The best way is to decide for yourself keeping in mind what people have already gone through.


![Yoda much to learn](https://thepracticaldev.s3.amazonaws.com/i/6tu0z4b0h9al59iwi6cd.jpg)

Please do point out any mistakes/typos/anything that can be improved in this post.