Is Scala difficult to learn?

(Note:  We may earn commissions from products/services you click on.  This is at no extra cost to you.)

Table of Contents

Scala is a powerful and, at times, thought-provoking language that is worth considering to learn. You can write exquisite code using it, but at the same time, without discipline, it provides a beeline for confusing code. Besides, it has some interesting libraries, such as Akka or Spark, whose API is better for Scala than for Java.

But it is difficult to learn the language, as it has unexpected things, special rules, and you can do the same things in several ways, which can lead to inconsistency in the codebase. Examples:

  • You can do the same thing in several ways; just check how to iterate through an array or how many ways you can use it. If that is not sufficient for the functional way of processing the list, you can do it with/if / = / yield or use methods from the List/map / for each filter, etc.
  • There are no operators; everything is an object, and every apparent operator is actually a method call.  This is extremely smart and powerful, but at the same time, without discipline, you can write code similar to Brainfuck.
  • Since operators are called a method, you can name them as you like, to have unexpected things, such as:: which is a method and a class name. Or you will have a code working perfectly, where ??? it is a global method that throws an exception.
  • Scala is a scalable, object-oriented, smokable programming language: therefore, the learning curve is a little steeper than Java, Python, or C ++.   In my experience, the biggest obstacle is understanding functional programming, as it is based on mathematical concepts, such as the theory of categories. In fact, it is more about getting into a new mindset than learning a new library, syntax, or structure.
  • Once done, it is just a matter of practice and taking advantage of the language’s subtleties. In fact, there is nothing specifically difficult about the syntax.
  • Remember that Scala opens the door to the use of large-scale structures, such as Spark and Kafka, and the development of machine learning applications.
  • In this context, learning Scala makes a lot of sense.
Is Scala difficult to learn
Is Scala difficult to learn

Is Scala worth learning 2020?

Java is a good language, and it solves many problems, a lot of people use it, it has many vacancies, it evolves well, it has fixed some errors of the past, as far as it goes, you would need to find the reason for not being worthwhile. Scala is a compiled language designed to run in a managed environment such as the .NET JVM or CLR. It offers the union of functional and object-oriented paradigms, especially on the Java platform. Support for functional programming and a modern compiler allows Scala to have a system of types verified at compile-time, as in Java, but with expressiveness and syntax similar to that of interpreted languages, such as Groovy or Ruby. However, Scala’s advanced features can also create performance and complexity problems.

Yes. It is worth learning.

Below are the reasons.

Widely used scala with a spark for real-time data analysis (Big Data)

  1. Scala supports both the functional concept and the OOP concept.
  2. So many frames are written in scala like Akka, Play, Lift, Spark, etc.
  3. You can stream data with Akka using scala.
  4. Currently, the opening of Scala is more but not less. Of experience, there are people available.
  5. Scala is faster than Java and Python.
  6. Scala helps to write both small and large applications.
  7. Spark is written in scala so that any new features are available first in scala and then in another language.
  8. Scala is less verbose.
  9. You can do batch processing in parallel in scala.
  10. Highly recommended for concurrency and distributed applications.

And the list goes on …

Currently, scala with spark is preferred for big data, over Scala with another framework. 

 

Is Scala easier than Python?

Scala and Python have the same expression, so the required functions can be achieved using Scala or Python. Python is a more user-friendly language than Scala. Python is not so verbose, and it is easy for developers to write scripts in Python to call Spark. Ease of use is a subjective factor because it depends on the programmer’s personal preference.

Performance comparison

Because Scala is based on JVM data analysis and processing, Scala is 10 times faster than Python. When writing Python code and calling the Spark library, the performance is mediocre. Still, if the program involves more processing than Python coding, it will be much slower than the Scala equivalent code. The Python interpreter PyPy has a built-in JIT (just in time) compiler. It is fast, but it does not provide various Python C extensions. 

 

The learning curve

There are several syntactic sugars when writing Spark programs in Scala, so big data professionals need to be very careful when learning Spark. Programmers may find that Scala syntax can sometimes drive people crazy. When using Scala, developers need to pay attention to the readability of the code. Compared with Scala, Java or Python is a flexible language with complex syntax. The demand for Scala developers increases because big data companies value-efficient and robust developers who can master data analysis and processing.

Concurrency

The complex and diverse infrastructure of big data systems requires a programming language that has the ability to integrate multiple databases and services. In the big data ecosystem, Scala wins in the Play framework and provides many asynchronous libraries and various concurrency primitives that are easy to integrate, such as Akka. Scala enables developers to write efficient, readable, and maintainable services instead. 

 

Scala vs. Python?

Python and Scala are a general-purpose programming language; it supports object-oriented paradigm.

 

Type discipline

 

Scala is a statically typed language, and we must specify the type of variables and objects in Scala. On the other hand, Python is a dynamic type language, and we don’t need to specify object types. But both languages ​​are strongly typed languages.

 

Compilation vs. Interpretation

 

Python is an interpreted language, and Python scripts will run line by line. Scala is a compiled language, all source code compiled before execution.

 

Platform

 

Scala is JVM based, Scala source code will compile into Java Byte Codes, and then JVM will run it. Python has many interpreters, CPython is the main implementation of PSF (Python Software Foundation).

 

Execution speed

 

Scala application execution speed is faster compared to Python applications (in CPython). 

 

Memory usage

 

Python’s memory usage is pretty good compared to Scala applications, and Scala applications will run by JVM. JVM is a virtual machine, so that it would take more memory. 

 

Libraries

Python has a large number of libraries for small or complex tasks. Scala libraries are small. But Scala has the ability to use the Java libraries. The Java libraries are huge.

 

Community support

 

Both languages ​​are open source, but the Python community is huge compared to Scala; even large companies like Google, Dropbox, and Facebook use Python. Scala also has good community support.

 

Functional Programming

 

Scala is a complete functional programming language. Python is not completely functional programming, but it supports many functional programming paradigms.

 

 

Scala vs. Java

The first and main difference that you will notice between Scala and Java is the short and concise code. Scala drastically reduces the number of lines in a Java application by using type inference, treating everything as objects, function passing, and some other features.

Scala is intended to express common programming patterns in a stylish, concise, and type-safe way. The language itself inspires writing code in absolute style, making it easy to apply concurrency and parallelism.

One difference that some might not notice is the learning curve. Scala has a sharper learning curve than Java; my opinion might be a little prejudiced because I come from a Java background, but with so much going on with so little code, Scala can be tough to predict. Scala’s syntax looks confusing and shocking compared to Java, but I’m sure it’s the initial impression. One way to eliminate this impression is to follow a good Scala book like Programming in Scala or Scala in Action; both are excellent books for a Java programmer who wants to learn Scala.

One of the interesting features is the included support of lazy evaluation, which allows delaying the calculation of operations that take a large amount of time until it is not necessary. 

Someone can argue that Java is more readable than Scala because of code nesting. Because you can define functions within functions, within other functions, within an object within a class, your code can be highly nested. Although clarity can sometimes improve, it cannot be easy to understand.

One more difference between Scala and Java is that Scala supports operator overcapacity. You can overload any Java operator and create new operators for any type, but as you know.

A big difference between Java and Scala is that functions are objects. Scala treats any method or function as if they were variables. This means that they can be passed as objects. You may have seen code where a Scala function is accepting another function. In fact, this gives great power to the language.

 

What is Scala used for?

It is a programming and scripting language based on Java and has existed since 2001. The idea behind it is that the Java language has been made scalable by combining object-oriented programming with functional programming. The power of both ways of programming is bundled into one language. Less code is needed here to write a class, the getters and setters are not needed, and Scala does not have primitives. In addition to classes, objects can also be defined here.

Within Scala, everything within a class is part of the primary constructor and the methods because it has a flexible programming syntax.

Developers, data scientists, and companies not only use Scala to create their new projects, but they also use other tools such as Play FrameworkApache Spark ( which I already explained to you in everything that could help you ), Akka or Kafka. In addition to being projects with great impact on the market, they were intentionally built in Scala.

Scala is executed on the JVM, allowing a union with Java beneficial for both languages and the developer, since he (or the teams) can program in Java and Scala at the same time ( does Kotlin sound like something to you? ). This symbiosis allows the integration of its characteristics and libraries, being able, among many other things, to inherit classes or implement interfaces.

We are talking about a multi-paradigm programming language that combines properties of object-oriented languages ​​with functional languages. For example, functions can be defined within functions, within objects that are within any class.

 

Scala resurgence

Even if you have never worked with it, you have surely heard of functional programming. And every day more, since it seems that there is hype with her. This programming paradigm, which seemed to have been forgotten by the great mass of developers, has resurfaced for a few years.

It has indeed been other imperative languages, especially imperative and object-oriented, that have earned the reputation of being more productive and effective for a greater number of tasks. But not everyone thinks the same. 

Why the resurgence of functional programming

Functional programming has been with us for many years, but it was always associated more with academic environments than business and productive environments. It seems to be beginning to change, and many companies, some very important, are betting heavily on this paradigm. Why?

One reason may be that applications are increasingly difficult to run on a single machine. It is increasingly necessary to be able to support large doses of concurrency and parallelism. Despite current hardware, it provides us with unprecedented parallelism capabilities, and the cloud is making it easier (and cheaper) to build distributed systems on different servers. And of course, for tasks like these, a functional language can unfold like a fish in the water.

Nor should we forget JavaScript, which has long had many functional concepts (anonymous functions, functions as first-class members, etc.). Being one of the most popular languages, it is easy for these concepts to reach more and more programmers, making the functional revolution go a little further.

But this does not end there, since to the old functional rockers, many new languages ​​are being added, with many other modern features. This is the case of Elixir, Clojure, Scala, or Elm, to name a few.

 

Is Scala is a dying language?

According to data engineers, scala is not a dying language as the Scala group is very efficient. At the same time, we are seeing a general industry shift to functional programming, and the time it takes will also bring some complexity growth to other parts of the modern technology platform, which may be a good thing. Scala is clearly regarded as a suitable inlay for distributed data processing, and now it is also driving the mainstream application of functional technologies. In this regard, she greatly benefited from the community of functional programming languages ​​full of enthusiasm. I don’t think the Scala group wants to see Scala “expand to all enterprises.” On the contrary, many people I have talked to have a consensus that a trend of Java types is not healthy. Java’s dominance and then stagnation for a century is not a good thing for programming. Therefore, continue to experiment, strive for growth, resist early standardization, simplify the language instead of accumulating language expansion-this is the healthy direction. Therefore, it is clear, editable, understandable growth, and iterating to an optimal state that can be approached but not reached is the healthiest development trend of Scala. 

The importance of Scala in the trend of mobile data and microservices is also obvious: In Lightbend’s recent survey of 2,151 JVM developers worldwide, 50% more Scala developers use microservices than Java. Among all the developers who use microservices, 35% use Akka, 30% use Kafka, and 19% use Spark. I compare them by extracting their daily time-series data from the GitHub databases of Akka, Kafka, and Spark. I observe three separate time series data: the total number of new observers, Pull Request, and Commit. The span of each data is from September 30th in 2013 to September 30th in 2016. For observability, I expressed these time-series data as a 2-week smooth moving average. 

 

Scala Tutorial

Getting started

This document is a starting point for Scala Language and Compilers. This document is for readers who have some programming experience and want an overview of what you can do with Scala. Readers are assumed to have a basic knowledge of OOP (especially Java).

First example

As a first example, we will use the Hello world program. It’s not a very attractive example, but it’s useful for explaining how to use Scala tools even if you don’t know much about the language itself. The Hello world source is as follows.

object HelloWorld {

def main(args: Array[String]) {

  

  println(“Hello, world!”)

  }

}

 

The structure of this program is pretty familiar to Java programmers. It consists of one method called main, and its parameters become arguments passed when executing. In other words, it is an array of Strings. Inside the method, a default method called println is called—passing “Hello world!” as a parameter. The main method has no return value. Such a method is called a (procedure method). If there is no return value, there is no need to define a return type as well.

The less familiar part of Java programmers is the object definition. This object owns the main method. This definition creates a Singleton object. As a result, this example creates a class called HelloWorld and an instance at the same time. Also, the name of the instance will be HelloWorld. Instantiation occurs at the time of first use.

The sensible reader will also find that the main method is not defined as static. Static members (methods or fields) do not exist in Scala. In Scala, Singleton is used instead of static.

 

Compiling

To compile the example, you need to run the compiler. Scala is the compiler. Like any compiler, scala takes the source file name and compilation options as parameters and creates one or more compilation result object files. Object files are Java class files. The above example

Assuming you have saved it as HelloWorld.scala, compile it by executing as follows. (The’>’ character means a shell prompt)

> scala HelloWorld.scala

 One of them will be HelloWorld.class, and this very class file contains classes that can be compiled with the scala command.

 

Running

If compilation is successful, you can run it with the scala command. Its usage is very similar to the java command. The options are also the same. The above example is executed as follows.

> scala -classpath. HelloWorld

Hello, World!

 

Conclusion

This document has provided a quick introduction to the Scala language and presented some basic examples. The interested reader can continue, for example, by reading the Tour of Scala document, which contains much more advanced examples, and consult the Scala Language Specification documentation as needed.

It should be remembered that it is not necessary to master the intricacies of Scala’s rich type system to use the language effectively. As you become familiar, you will begin to create powerful and sophisticated libraries to increase your productivity.

The language specification describes the formal details of the type system. Like any specification, it cannot be easy to read, but it’s worth doing if you want to know the system’s type in depth. There is also a long series of articles on Scala’s type system, which you can find from its official site.

In the next two chapters, we will analyze the practical aspects of software design and the tools and libraries to develop applications in Scala.

Scala is an elegant, expressive programming language. It is mature, generates efficient code, and brings a good integration into the common Java IDEs, including support for interactive debugging. Scala represents a successful, pragmatic combination of functional and object-oriented programming. It contains many of its own libraries and can be seamlessly integrated with the Java or .Net platform to use the existing wealth of frameworks and libraries. The programming language is definitely solid enough for commercial, productive use – and for the fun factor alone, it is definitely worth a closer acquaintance.

 

 

 

Luis Gillman
Luis Gillman

Hi, I Am Luis Gillman CA (SA), ACMA
I am a Chartered Accountant (SA) and CIMA (SA) and author of Due Diligence: A strategic and Financial Approach.

The book was published by Lexis Nexis on 2001. In 2010, I wrote the second edition. Much of this website is derived from these two books.

In addition I have published an article entitled the Link Between Due Diligence and Valautions.

Disclaimer: Whilst every effort has been made to ensure that the information published on this website is accurate, the author and owners of this website take no responsibility  for any loss or damage suffered as a result of relience upon the information contained therein.  Furthermore the bulk of the information is derived from information in 2018 and use therefore is at your on risk. In addition you should consult professional advice if required.