Learning Scala: From the outlook of Computer Sciences

Scala has emerged as a top tool for data management

Before learning any programming language, most people jump on to learn the syntax directly and get themselves ready to code some tedious project without actually understanding the underlying concepts and the programming model. So, I am writing this fun blog while learning Scala as a part of my college project.

I’ll be trying to cover a lot of content in this one, so I suggest you to grab a cup of coffee too alongside !!

Features of Scala

  • Scalable Language: Well, Martin Odersky modified the legendary Java for a reason! Its powerful frameworks like Apache Spark makes it just the tool a developer would want while working with some incredibly huge databases.

One of the most classic examples to demonstrate the power of Scala is Twitter.
When first introduced, the developers involved with Twitter back then used Ruby on Rails as their primary programming interface. But soon, they were caught in the loop of big data, which was coming in (only from the United States back then), and they consequently had to make a transition from Ruby to Scala, which, of course, builds on Java.

If you know how cool Rails is when we talk about scaling, you might have realized the power of Scala.
  • Concise: For people who might be arguing over the fact that Python is better than Java, the first thing they’re going to point out has to be the object structures of Java. For typing down a simple { Hello World } program, you’ll have to type a minimum of six code lines in Java for it to compile and run successfully. But in comes Scala to protect you against those who worship the snake!! Scala minimizes the code length and reduces the execution time to a great extent.
  • Distributed Data Analysis: Ever heard about Big Data? If yes, then Hadoop and Spark are all that you need.
  • Multiple Paradigms: Scala inherits in itself properties of both Object-Oriented Languages and Functional Languages. So, consequently, it inherits all the classic features of these two paradigms. These include lazy evaluation [Haskell ;) ] and immutability. One interesting thing to note down is that Scala is not fully immutable, making it super cool for me!!
    We have these two types, var, and val, for a variable declaration, which gives us full control over the variables’ internal state throughout the program execution.

But wait a minute Kartikeya, you aren’t doing any justice to the title of this blog. Yeah, calm down, pal. In the next section of this blog, I’ll be covering some terms I came across while learning Scala as a newbie to this part of computer sciences. At first, you might find those terms a bit weird but stay with me to discover the complexities.

  • Scalability: This one was quite intuitive in itself. We talked about working on big data sets with Scala, right?
    Scalability refers to the ability of a programming solution to handle increased loads of work. If your program can do something working with a database of fewer than 1000 records, if it’s scalable, then it should be working pretty fine with datasets that would be exponentially large compared to the previous one.
  • Concurrency: A concurrent program simply refers to a program that does several tasks at once or when two tasks overlap in execution. These tasks are generally assigned to different cores or processors on a machine.
    The most common thing I can think of is the OS kernel. Okay, that isn’t as easy as it appears to be;)There are several caveats which concern the decision of making this a different realm of programming. If your program is concurrent, you might have deadlocks for outputs to be displayed, different queries might start to interfere with each other, and whatnot. And with the evolution of octa-core processors, the understanding of concurrency becomes quintessential.
  • Parallelism: The term parallelism refers to techniques where the tasks are divided into smaller sub-tasks computed simultaneously. It is used for increasing the computational speed of the system by using multiple processors. Parallelism is when numerous copies of the same program are run simultaneously but on different data.

Well, the above two terms might have perplexed you a bit. So, simply remember:

“Concurrency is more about running multiple queries together while parallelism is more about simultaneously computing several sub-tasks related to a single query.”

Octa-core and Quad-core processors have brought in a revolution for computing processes.
  • Statically-Typed vs. Dynamically-Typed: You might be aware of this one. Statically typed refers to the data types for variables being detected/ checked at the compile time itself, which gives it runtime safety. Consequently, dynamically-typed is one where the type is checked at the runtime.
  • Extensibility: Well, calling a programming language extensible simply means that you can define your plugins for the language.
    Sorry, precisely what? By plugins, we refer to some additional mapping that can be defined and may be used later. One such example I remember is about defining Roman numerals corresponding to various natural numbers.

So, here you go. Scala is extensible, and that too to a great extent. Its extensibility makes it even more powerful. Moreover, Scala is a statically typed language, so there are always defined sets of types, and anything that doesn’t fall inside that set is classified as an invalid type, and an appropriate error is thrown at compile time.

Scala was built keeping all these revolutions in mind and had some brilliant inbuilt features to keep you away from the low-level computation. At this moment, I quote some insights taken from the official Scala docs.

Parallel collections were included in the Scala standard library to facilitate parallel programming by sparing users from low-level parallelization details while providing them with a familiar and straightforward high-level abstraction. The hope was, and still is, that implicit parallelism behind a collections abstraction will bring reliable parallel execution one step closer to mainstream developers’ workflow.

With this, I think I’ll be concluding my blog. I hope this blog gave you some insights into thinking about a programming language’s cores and fundamental basics. And talking about as to why I chose Scala, it was primarily because of two reasons: firstly, I think Scala is one such language that addressed some real-time issues when it was first introduced, and secondly, because in my opinion, learning any programming language after doing functional programming for more than a week makes you feel way too good about it.
Thanks for reading all the way down. Do you share your valuable feedback!

Happy Coding!

I am a Sophomore at Indian Institute of Technology, Kanpur. I am interested in Algorithms, Robotics and Cognitive Sciences.