Scala is jet another programming language in the world of programming languages. Its first version was released in 2001 and was conceptually developed by Martin Odersky, a professor at the EPFL in Switzerland. Fun fact: one of his first projects was called Pizza and was a super set of the Java language. Later on, he developed Scala. The name and logo are easy to explain. First of all, Scala stands for SCalable LAnguage. Another translation: “Scala” means “staircase” in Italian. The logo is based on a particular staircase in one of the buildings of EPFL. Now we have had a decent introduction to Scala, we can start exploring the language itself. So what is Scala all about?
Is it a functional programming language? Is it an object-oriented programming language? The answer to both questions is yes! Scala is a object-functional programming language. The good old well-known stuff is all in Scala. You can build complex applications by the means of objects and classes. On the other hand, Scala tries to teach programmers a paradigm called functional programming. In functional programming, a computation is treated as the evaluation of a mathematical function. So in that sense, everything in Scala is an evaluation. You might wonder why you would ever need functional programming if you are used to object-oriented programming. Well, the case is that in imperative programming you are changing the state over and over again. This is not allowed in functional programming. The changing of the state causes side-effects and makes your application less transparent. A imperative application is therefore often hard to debug while a functional program is easy to debug since it does not change the state. A concrete example is given below:
Imagine that you run a large software company. If you would decide to use imperative programming, you can count on many hours of debugging. So to cut down the costs, you definitely want to use a functional programming language. But a functional programming language also has its downsides. It is hard to get the hang of functional programming if you have never worked with it. Scala solves this problem by allowing both paradigms, so you can shift to the paradigm of functional programming. Suppose our large software companies has 100+ employees which have no experience with functional programming. It would be a huge cost to decide to move over to a purely functional programming language. Here, Scala can be used for moving over to the new paradigm. Another downside is that it is really hard to estimate the time and space costs of lazy functional programming. In these types of code, evaluation is done when it is needed, so it is hard to predict when evaluation will happen. So, in fact Scala tries to shift the often used imperative paradigm to the functional paradigm.
Scala does not throw away all the good stuff of your software company. Suppose your company has written over millions of lines of Java code. Scala is completely backward compatible with Java! In fact, you can even use Java tools like Maven to install dependencies. Scala also has its own build tool (SBT which stands for Scala Build Tool). Scala is in fact a Java package and extends the Java language. A good thing to know is that Scala can dramatically decrease the number of lines of code you have written in Java. It also makes concepts in Java easier. One concrete example is that you do now have to specify the type of a variable. Scala will figure out the type for you. But if you really need to specify a specific type, you are free to do so. Compared to a language like Python, Scala is a bit harder to learn. In fact, you need to know a bit of Java if you want to learn Scala easily. It is also easier to run Python applications. For Scala, you need to build your whole application. But if you would write an application which will be used in a production environment, you would definitely want to use Scala for that. The reason for that is that the Scala code is compiled to Java bytecode and this runs way faster than the Python IDE. Scala therefore is a compact programming language which is even backward compatible with Java and relatively fast compared to other modern programming languages.
Scala is used in many applications. In the following list, I will name a few:
- Apache Flink – A Streaming Processing framework. You can write code for Apache Flink in Scala.
- Apache Spark – A Batch/Streaming Processing framework based on (micro)batches. You can write code for Apache Spark in Scala.
- LinkedIn – Yes, LinkedIn is using Scala.
- Twitter – Also Twitter is using Scala.
- Sony – And also Sony uses Scala.
I would definitely recommend the following book (written by the inventor of Scala): Programming in Scala – 2nd edition (by Martin Odersky, Lex Spoon and Bill Venners).
Stop using Java and start using Scala. You will experience a transition from imperative programming to functional programming and gain the benefits from it. It is used by many companies and it broadens your perspective as a programmer. Compared to other modern programming languages as Python, it runs a bit slower. But once your code is compiled it will run way faster.