Could Scala the Best of Both Worlds?

Jul 12th 2020

By Robert Kirchner JR


Scala an Alternative to Java?

Scala is a high level language run on the JVM. It is known for the ability to be used in both object-oriented and functional styles. We will look at how it does as both.

Scala Logo

Object-Oriented Programming

The concept behind object oriented software is quite simple, all the data and business logic in your application, are encapsulated in small(hopefully), modular objects.

An entire program being an intricate web of these objects, carefully(hopefully) wired together working in harmony to transform your data, or whatever you need software for.

Object Traits

There are two characteristics that every object can have(your objects only have one or the other if your good), state and behavior. State being actual data, and behavior being some kind of functionality, be it manipulating data, or something else.

A common, and also good example, might be a user on social media. A user has state, a username, email address, status... And a user also has behaviors, logging in, commenting on a post.

This is probably the most common uses of programming objects. Typical mature object-oriented software languages have some very powerful advanced features. Inheritance, polymorphism, encapsulation and abstraction. Those being what are called the four pillars of object-oriented programming.

The Downsides of OOP

Mutability

Data stored in memory, that can be manipulated, mutated and totally reassigned is said to be mutable. At first glance this seems quite natural for computer programs.

But in a world of multi-core CPUs, and multi-million user applications, mutability can have very negative effects.

Mutable data can easily become corrupt when being manipulated by more than one process at the same time.

Synchronization

Synchronization is the act of purposely de-parallelizing work in order to avoid corrupting data. As you can guess, this can significantly slow down software and lead to race conditions and deadlocks.

Side Effects

A side effect is when a method, or some operation doesn't return anything. It goes on its own and mostly mutates state. Side effects can cause undesired and unexpected behavior.

Functional Programming

Functional programming is based behind the concept that software components are not objects but pure functions.

Pure Functions

Pure functions are a mathematical concept in which a function or operation takes an input, and returns a single output. And given the same input, returns the same output. Pure functions do not have side-effects.

First Class Functions

In functional languages, functions can be returned and passed around like any other data variable.

Scala

Scala is an extremely complicated language that is run on the Java Runtime Environment. Scala is named to be a scalable language, that is strongly typed and can be used in both object-oriented and functional style.

OOP and Functional Features

Immutability

Scala is a very popular choice for big data applications. This largely due to the focus on immutability. In Scala all data and collection types are immutable. This makes them safe from corruption in heavily multi-threaded environments.

Case Classes and Pattern Matching

Case classes are classes that only have a definition, and are perfect immutable data beans. Pattern matching, especially when used with case classes, is the ultimate replacement for the dreaded switch statement.

Static Objects

The notion of a static object is a perfectly static helper class. These are often used as companions and give functionality to case classes.

Traits

A trait is Scala's take of the ultimate abstract class. Traits can contain both method contracts, but also override-able concrete method implementations. A child class can implement multiple traits using the with keyword, simulating multiple inheritance.

Implicit Parameters

Another noteworthy feature of the language known as implicit parameters. Implicit parameters are special because the don't to be supplied during a function call, the interpreter goes off and finds one of the correct type.

Option and Named Arguments

The Scala option is a more robust and less verbose version of Java's optional(jdk8). Options can be used with patterns that prevent the dreaded null pointer exception. Named arguments can be a powerful tool, especially when paired with options and case classes. These patterns allow our immutable bean objects to possess default values, and using named arguments, we can declare them with only the arguments that are needed.

Functional Parameters

With functional parameters, Scala allows us to pass functions as parameters, and also the luxury of factory functions.

Futures

Scala, being a scalable and big data language, is heavily focused on multi-threading and parallel asynchronous processing. Scala's future allows our functions to return us a promise that we can call on when it is done processing.

Java

Being a JVM language, Scala provides the ability for you to use nearly any Java library or features. With very little effort, you can use nearly any Java code, this helps makeup for some of the features that Scala lacks.

My Take on Scala

Popularity

Scala gets most its popularity from the big data industry. But this does not make it a popular or high demand platform. Fact of the matter is that Scala peaked in popularity years ago. If you were to try to hire a team of Scala engineers, you might have a hard time filling your roster. Not too many people are practicing it.

Complexity

Scala has been one of the, if not the most complex language I ever set out to learn

Inversion of Control

Not only does Scala have means for dependency injection, but lets not forget the Scala implicit. Dependency injection is usually a welcomed form of the inversion of control, but implicit s have the tendency to add a layer of mystery around how the interpreter decides what argument it will actually provide. If not executed perfectly, they can produce strange behavior that is hard to debug.

Compiling

Since Scala runs on the JVM, it is compiled into Java byte code. It turns out this process is heavy duty, and can take an absurd amount of time. This tends to be very painful to engineers, especially when coupled with test driven development.

The simple build tool(SBT) can also make compile time painful. It tends to be very fragile, and most IDEs don't recognize its syntax as valid.

Type Inference

Type inference is one of the Scala features I actually do like. It helps Scala to accomplish it's goal of being less verbose than Java. But it is true that excessive use of type inference and syntactic sugar can make it difficult to read and maintain code.

Functional parameters can have the same effect. Functional parameters tend to make function/method definitions messy.

Use Cases

Scala lacks some basic functionality, forcing you to use Java as a means to perform low level tasks. Scala works best in an API or web service use case. Given Java's already rich network socket features, Scala is a good choice for this case.

Community Support

Google can be a software engineers best friend. When faced with an obscure problem, you can typically find solutions on several of the many community support sites. Given the lack of popularity of Scala, this is not often the case.

Conclusion

Scala strives to be a scalable, robust and easy to read big data JVM language. Scala can be used in both object-oriented and functional flavors.

Their is a strong focus on immutability, that makes Scala a great candidate big data and concurrent processing applications.

Scala is very complex and difficult. It is not very popular, nor high demand, and this can make it hard to find developers for your project dev team.

Comments


03/31/2021 04:01


Link exchange is nothing else but it is simply placing the other person's webwite link on your page att appropriate place and other petson will also do similar for you. Pharmacologie du sport site Dees sports


03/30/2021 19:49


Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how could we communicate? area domino


03/24/2021 19:56


<a href="https://youtu.be/IKUZYHz7Rv0">???????? ???????? ??????</a>


03/12/2021 19:12


You can certainly see your skills in the article you write. The world hopes for more passionate writers such as you who are not afraid to say how they believe. At all times follow your heart. dominoqq


03/11/2021 16:37


Wow! After all I got a weblog from where I be able to really obtain helpful data regarding my study and knowledge. poker online


03/10/2021 14:53


??? ??? ?? ?? ?? ??? ?? ???? ?????? ????.


03/05/2021 22:23


It's very straightforward to find out any matter on web as compared to textbooks, as I found this post at this website. my webpage :: ??????


03/01/2021 17:12


Excellent blog here! Also your web site loads up very fast! What web host are you using? Can I get your affiliate link to your host? I wish my web site loaded up as quickly as yours lol bandarq


02/26/2021 05:10


I visied several web pages but the audio quality for audio songs existing at this weeb page is actually fabulous. Natürliches potenzmittel homepage Kamagra Brausetabletten


02/25/2021 06:08


Do you have a spam problem on this blog; I also am a blogger, and I was wondering your situation; many of us have created some nice practices and we are looking to trade techniques with others, please shoot me an e-mail if interested. mitra 13


02/25/2021 00:53


Verry nice post. I just stumbled upon your weblog and wnted to say that I've truly enjoyed surfing atound your blog posts. In any case I will be subscribing to your feed and I hope you write again very soon! Binêre denke homepage marketsworld


02/18/2021 21:32


I am regular reader, how are you everybody? This post posted at thius site iis in fact good. How to plump lips permanently webpage top perfumes


02/18/2021 17:38


That is a good tip especially to those new to the blogosphere. Simple but very precise info??¦ Thanks for sharing this one. A must read post! Cypfus investment fund homepage investors


02/18/2021 06:58


generic sildenafil buy viagra cheapest price https://mail.a-tomy.net/forum.php?mod=viewthread&tid=2559602 - buy generic viagra usa canadian pharmacy viagra no prescription viagra samples generic viagra lowest price


02/18/2021 02:57


Good article! We are linking to this particularly great content on our site. Keep up the great writing. dominoqq


02/16/2021 20:28


Heya i am for the primary time here. I found this board and I in finding It reawlly helpful & it heelped me out a lot. I am hoping to provide something again and help others such as yoou helped me. ?????? ?????? ???????????? homepage ?????? ????


02/13/2021 09:04


I will right away grab your rss as I can nott to find your email subscription link oor e-newsletter service. Do you've any? Kindly let me recoghize soo thhat I may subscribe. Thanks. ????????? ??? homepage ??????????????


02/11/2021 05:30


It's in point of fact a nice and useful piece of info. I'm happy that you shared this useful information with us. Please stay us informed like this. Thanks for sharing. ?? ???? homepage ????? ?????


02/10/2021 07:49


There is certainly a lot to find out about this issue. I really like aall the points you have made. Viagra 25mg web page acquista erofertil in italia


02/09/2021 23:12


Excellent post. I was checking continuously this blog and I'm impressed! Very helpful info particularly the last part :) I care for such information a lot. I was seeking this certain information for a long time. Thank you and good luck. dominoq


02/09/2021 18:14


Yes! Finally something about ?????????????? ????? ????????. ??????? ??????????????? ?????? web site ????????? ???????


02/08/2021 15:11


If some one desires expert view concerning blogging afterward i recommend him/her to visit this weblog, Keep up the fastidious work. situs judi


02/07/2021 17:25


Thanks for sharing your thoughts about scala. Regards ?????? 4 ????????? ???????? web page ?????? ??????? ???? ????


02/06/2021 19:16


?or most ?ecent news you have to pay a visit the weeb ?nd on web ? found this site ?s a finest website for ne?est updates. Caan ?ou Here is m? web-site: bandar Togel online


02/06/2021 08:11


Ver? nice article. I ?bsolutely ?ppreciate th?s website. Keep it up! Wou?d Youu M? blog post; situs judi slot online


02/05/2021 20:12


This web site certainly has all of the information I needed concerning this subject and didn't know who to ask. Professional rsume writers web page resume writing services near me


02/02/2021 09:40


Hi there, all is going perfectly here and ofcourse every one is sharing information, that's truly fine, keep up writing. situs judi


01/31/2021 08:38


It's remarkable in support of me to have a site, which is useful for my experience. thanks admin ????????? ????????? web pagbe pajero sport


01/29/2021 17:16


Amazing! This blog looks exactly like my old one! It's on a entirely different topic but it has pretty much the same layout and design. Excellent choice of colors! kotakqq


01/25/2021 18:13


It's actually very complex in this active life to listen news on TV, so I only use internet for that purpose, and obtain the hottest information. ????????? ??????? homepage ??????? ???????????


01/25/2021 03:04


Hi there, this weekend is pleasant in support of me, as this point inn time i am reading this impressive informative post here att my home. ???????? honda web site ????? ???? ????


01/23/2021 19:27


Nice blog here! Als? y?ur site loads up ?ery fast! W?at host are you using? Cann I get ?ou? affiliate link t? y?ur host? I wizh mmy site loaded ?p a? ?uickly as yours lol Would Yo? H?re is my pag? ... judi togel


01/22/2021 13:24


I rea?ly like it whenever people get together and share opinions. Great website, stick with it! Would Y?u my blog ?ost ... Sit?s ?l?ot Terbaik


01/22/2021 10:36


Hi there colleagues, its great post concerning teachingand fully defined, keep it up all the time. pkv games


01/17/2021 10:33


You a?? some decent ?oints there. I looked ?n the net for more ?nformation ahout the issue and found mo?t individuals will go along with you? views on this site. Would Y?ou Here is my blog - Judi Slot


01/16/2021 20:02


low priced aurogra


01/13/2021 19:40


Hi, yes this piece oof writing is really nice and I have learned lot of things from it concerning blogging. thanks. Levittra Generico prezzo site migliore farmacia online


01/13/2021 07:00


walgreens generic dapoxetine price


01/12/2021 14:21


Wow, wonderful weblog format! Hoow lengthy have you been running a blog for? you mawde running a log glance easy. The entire glance of your site is fantastic, as neatly as the content material! ?????? ?????????? website ??????? ??????


01/06/2021 02:05


gookerdoughboy777 https://gookerdoughboy777.blogspot.com/2020/12/coldcagmag999-watch-online.html It's fantastic that you are getting ideas from this piece of writing as well as from our dialogue made here.


01/06/2021 01:08


Ada baiknya anda sering-sering mebaca berita dan prediksi bola di https://www.bolamoe.net/ agar anda memeiliki pengetahuan tambahan tentang sepakbola yang baik dan benar.


01/05/2021 23:16


gookerdoughboy777 https://gookerdoughboy777.blogspot.com/2020/12/coldcagmag999-watch-online.html Superb, what a webpage it is! This weblog presents helpful data to us, keep it up.


01/02/2021 15:52


???????? 1???? ?? promokod-x.ru: ?????? ??????? ?????????? ??? 1???? ?? ???????. ?? ????? ????? ?? ??????? ????????? ?? ?????? ?????: ?? ???????, ?????????? ? ???????


12/22/2020 04:17


Nice blog here! Also your web site loads up very fast! What web host are you using? Can I get your affiliate link to your host? I wish my site loaded up as quickly as yours lol Here is my web site :: viagra online


12/15/2020 03:40


Your way of telling the whole thing in this article is truly pleasant, every one be capable of without difficulty be aware of it, Thanks a lot. situs judi online


12/06/2020 02:33


???????? 1???? ?? promokod-x.ru: ?????? ??????? ?????????? ??? 1???? ?? ???????. ?? ????? ????? ?? ??????? ????????? ?? ?????? ?????: ?? ???????, ?????????? ? ???????


12/02/2020 02:45


Thanks for sharing your thoughts. I really appreciate your efforts and I willl be waiting forr your next post thank yoou once again. ?????? ??? ????? webpage ??????? ??????


11/30/2020 21:50


I kjow this site offers quality based articles or reviews and additional material, is there any other webb site which ofers these stuff in quality? ??????? ??????? ??????????????? wweb site ????? ????????????


Navagation