Insights on Scala

Reading Time: 2 minutes

Whenever we start learning a new language, we tend to jump straight towards the syntax and writing the so called “Hello World” application. Do you ever wonder why a particular language exists in the first place? What are its characteristics? Well, if you didn’t, I did. Here are some insights on Scala.

Scala is a language that can grow in new directions.

With Scala one can add new types and constructs, which can be used as easily as the built in types and constructs. And, it is extensible to such an extend that if you knew about Akka you would know that it’s a library(for concurrent programming). It’s built on top of Scala, which makes us feel like that this is a built-in feature of Scala. One can built new functionality on top of Scala and use it as if they were built-in.

What makes Scala scalable?

Scala is a fusion of object-oriented and functional programming concepts. Scala is purely Object-Oriented unlike Java. In Scala, every operator is a method and primitive types are classes. Whereas in Java, primitive types are not classes and static members of a class are not members of an object. Which is why Java is not purely object-oriented.

Other factor which makes Scala scalable is being functional. So, there are two main concepts in functional language.

First one is “Functions are first class values”. That means a functions holds the same status as any other object of primitive types or user-defined types. Which means, a function can be passed as a parameter, returned as a result, stored in a variable, and defined inside a function.

Second is, methods should not have side effects, which means a method should operate on some input values and return the result after the computation on the input values. Another way of explaining referential transparency is, if you replace a method call in your code with the result by that method call with relevant input values, it would work as if nothing changed. Whereas, if a method is side-effecting in nature then you would not be able to replace it with anything.

Immutable data structure also adds to the list of factors making a language scalable. Immutability rules out the risk of race conditions in a concurrent environment.

Important aspects

Compatibility
Scala runs on JVM. It seamlessly interoperate with Java. And, Scala programs compiles to JVM bytecode which in fact, has run-time performance comparable with Java programs. So, using existing Java code in Scala is nothing different, you don’t need patching or glue code or any special syntax.

Concise
Fewer lines of code not only saves us from typing more but also has fewer possibilities of defects, less efforts to read and understand(if followed clean code practices). A one liner case class in Scala is similar to an entity class in Java which might be of 15-20 lines normally.

High Level
To manage complex requirements, high level abstractions come into picture. The higher the level of abstraction the lower the details and lesser the complexity. Control abstraction is something Scala provides, which a programmer can leverage to use his/her own abstractions.

Statically Typed
Static typing adds value to Scala as it reduced the verbosity of mentioning the type. It still keeps the type safety at compile time.

I hope you get to know Scala better than before.
Visit here to know about Scala constructs.

Reference
https://www.artima.com/pins1ed/a-scalable-language.html

Knoldus-blog-footer-image