March 7, 2019

Srikaanth

Major Reasons Why Scala Is Better Than Java Programming

7 reasons Scala is better than Java ... so why is Java winning?

Java has steadily grown in popularity over the past twenty years and now sits at the top of many “most popular” programming languages charts. Leveraging the power of object oriented languages and combining that with memory management as keystone language features turned out to be a powerful formula for success. (C# on the Windows platform side is also in the Top 4 with similar characteristics.)

Java is a good language, but it has some issues. Scala solves some of those fundamental issues and then goes a step further to provide developers much more than Java is capable of today. For those who are hearing about Scala for the first time – or who have heard about it only in passing – let’s begin with a brief look at the history of Scala.

Scala Basic Common Interview Questions and Answers


Scala history:

Martin Odersky did development work on the Java language in the late 1990s, soon after Java was released. He discovered various issues with the language that were baked in and unlikely to change … ever. He believed there was simply a better way to build a language, and this motivated him to develop the Scala language. However, he didn’t want to start from scratch because he believed doing so would present too great a barrier to developer adoption, given that there would be no existing libraries or tools to support Scala. So he developed Scala “on top of” Java ─ not as a Java extension but as a language that could connect to the existing Java infrastructure, leverage its tools and libraries, compile to Java byte code, and be independently developed to solve the problems inherent to the Java language. Odersky started developing Scala in 2001 and released the first version in 2003.

Major Reasons Why Scala Is Better Than Java Programming
Major Reasons Why Scala Is Better Than Java Programming


Now, thirteen years later, how is Scala doing? If we are looking at just the most “popular” languages, by any measure Scala has not been widely adopted. (Granted, describing the most popular languages is problematic on several levels.) Most articles that list popular languages make no mention of Scala. The TIOBE Software company seems to be acknowledged as one of the definitive authorities on programming language usage. They rate “number of developers using the language,” and Scala comes in at number 30 with a rating of 0.532% (as of February 2016) coming in behind antiquated languages such as COBOL, Fortran, and PHP. (OK … I know. PHP isn’t antiquated, but let’s be honest, it’s time for people to move on).

Reason 1. Options

Anyone who has done non-trivial software development for any length of time has run into the dreaded “null pointer exception” (or one of its dozen variants). Scala Options don’t solve this problem by addressing it head on, but they provide a mechanism for a smart programmer to avoid the issue in myriad situations where it would typically present itself. Since moving to Scala and understanding the power of Options in this regard, I have seen a massive decrease in the number of runtime null pointer exceptions in my own code. It has made numerous everyday coding solutions much easier to handle appropriately and concisely.

Reason 2. Play Framework

Play Framework logoThe Play Framework is a full-stack web framework for Scala and Java. So why, you may ask, is this an advantage unique to Scala? Well, for one, the Play Framework was developed for Scala. The guys that developed Scala and branched out into the Typesafe company understood that a modern programming language must have a web platform to support it, or it would be rejected out of hand. So many of the features and technology behind the Play Framework are best leveraged using Scala. For example, Java was developed primarily around the “Servlet API,” which is essentially an abstraction layer over the web’s own architecture. This is sub-optimal simply because the web is more important than Java. Using Play with Scala, developers can embrace the architecture of the web and deal directly with an API that embraces HTTP. Lastly, the Play libraries built for Scala around interacting with JSON and XML have far exceeded what is available in Java and have bridged the gap between data and code unlike anything available in Java.

Reason 3. “for” ...what?

Scala has a very robust set of collections and built-in functions for those collections that generally make working with collections much easier than in Java. In fact, the difference between using Java and Scala collections, in terms of built-in functionality, is so stark that it is typically very rare to find “for” loops in Scala code – they are simply a sub-optimal way to apply operations to collections in most cases. The Scala collections are smarter and much easier to use in an intuitive way to apply business logic to collections.

Reason 4. DSL capability

Scala has numerous features (e.g., the ability to pass functions as objects) that make it very easy to develop domain specific languages. While DSLs are typically (and usually accurately) portrayed as only applicable to a narrow range of problems, there is reason to believe that this may not be the case in the future as Scala enables DSLs and embraces features to support DSLs in a way that Java cannot.

Reason 5. Functional orientation

Object-oriented (OO) programming is here to stay, and Scala is at its heart an OO language. But the developers of Scala also recognized the incredible value proposition of functional programming (the ability to develop code without considering state). They built features into the language to not only support functional programming but to encourage it. I come from a C++ background early in my career. I embraced .NET through its evolution and have programmed in Java and Scala extensively. Object-oriented programming is in my blood. However, the advantages of functional programming are clear and should be embraced at every opportunity. OO and functional are not at odds, but rather provide two different ways of solving problems. Recognizing the advantages of both and moving seamlessly between the two allows developers to build more robust and extensible code.

Reason 6. Semicolon

Really, do we need a visible delimiter all the time? Scala figured it out … the answer is: “No.” You need one only when there isn’t another much more natural delimiter (like newline).  Enough said.

Reason 7. All the reasons I’m not giving their proper due

I am only one developer, and the first six items are just what comes to mind after developing web services in Scala for the last four years. I have literally never met a developer  who had taken the time to learn Scala who didn’t agree that it was “better” than Java. So No. 7 is for them – for all the coders out there who didn’t find their pet pro-Scala point on my list.

So the elephant in the room is, after thirteen years, why is Java so much more popular than Scala? That’s a really tough question. Getting an answer would probably require psychologists and sociologists, as well as computer scientists and engineers. Lacking that, here is my professional speculation.

The Learning Curve

As previously mentioned, I worked for years with C++, C#, Java, and Scala. I have also done non-trivial coding in Python, PHP, and Javascript. (I won’t be sucked into putting HTML and CSS on the same level as real programming languages.) Without exception and by quite a margin, Scala was the most difficult language to learn. Every Scala savvy developer I know says the same thing – it has a steep learning curve. That’s a barrier to entry in and of itself. If a seasoned developer has a hard time picking up a language, it’s easy to imagine that it is exponentially more difficult for a beginner.

The Complexity

Software developers, like most people, love to be clever. But we get to be clever in a special way – we can write clever code that we know someone will eventually read and see how clever we are. This is nothing new. Developers probably have been doing this since the punch card days. (I wasn’t around then, but in my head this looks pretty funny.)

Experienced, forward-looking developers tend to suppress this urge. After you write code that you yourself can’t read six months later, being clever loses its shine, and you trade it in for maintainability and extensibility. Compared to other languages Scala makes it far easier to be clever. Indeed, sometimes the obvious way to write code in Scala (to leverage features of the language) produces code that is very difficult to interpret, particularly if you didn’t write it. So Scala code naturally looks “complicated.”  It takes real effort on the part of a Scala developer to write code that is highly effective and maintainable (i.e., it’s hard to make it work really well and be easy to understand for the programmer who has to read the code in six months).

In my opinion, those two factors are the reason Scala has not dominated the developer market the way that Java has.

Scala coders hard to find

More problems result  from that lack of developer adoption: Scala developers are harder to find, and training those willing to take a job on a Scala project is more difficult (expensive). This means that while some enlightened group may set off down the Scala road, managers quickly discover that expanding or replacing developers on the team is hard and resistance to Scala’s expansion thus moves beyond the bounds of the technology itself.

Scala is well supported as a niche language today – the Typesafe company has done a great job of developing a grassroots following. I would highly recommend picking up Scala if you have the time and dedication to put in three months of work to learn a language. It will make you a better programmer. But until the software market moves beyond the startup/adoption cost to Scala, or the folks behind Scala evolve it into something more easily consumed, it will probably remain the quirky language that runs on top of the JVM, literally and figuratively.

Scala Basic Common Interview Questions and Answers

Source: HP


Subscribe to get more Posts :