Scala VS Java: another view
JVM is too small for two leaders. That’s how I want to start a post about Java vs Scala. By the way, I had used Java for a long time, but then switched to Scala and wasn’t happy with that decision. Luckily I have understood how to use its features in order to be more productive developer. Make yourself comfortable, it’s going to be a very interesting conversation about marketing in a programming languages world. Yes-yes, exactly conversation, because I encourage my readers to write comments with their thoughts about the topic.
Firstly, I want to guide you through brief stories of two competitors. This will be helpful because I’m going to refer to the historical facts. Furthermore, recalling the main phases of Java & Scala development will give us a pretty accurate prediction of their future. Let’s start a journey back to the days.
The Java way
In 1995 Java was released. It was some kind of revolution. You probably know why, but I’d like to explain my vision of that fact. Here is a list of Java killer features:
- Runs on any platform (of course JVM is required)
- A code written once runs anytime (back compatibility)
- Garbage collector (no need to manage a memory)
- Classical object oriented paradigm
- Syntax (almost the same as in C++)
So looking at the list above you can easily imagine what problems were crucial for developers in 1995. Since that time Java has been updated many times. The number of Java developers has grown so incredibly. Now Java is an undisputed leader among programming languages, especially in a context of server-side development. In order to prove it I suggest you to refer to TIOBE index, PYPL index or GitHut statistics:
Of course you can find any other statistics, but I bet Java also will be there in TOP-3.
What is the reason of such popularity? Well, that is the list of Java advantages published above. Definitely they gave extremely strong impulse to the future development of the programming language. But to be honest, the success of Java on a such long distance was provided by the important and useful features introduced from release to release.
All these factors sound well until we recall what moves the tech world. Java was created by Sun Microsystems and then in 2010, Oracle has acquired it with all the consequences. Huge amount of money is invested in Java: conferences (JavaOne), Java Champions program, Java Magazine, movies (Oracle placement in Iron Man 2), promo videos…
As you can see, Java with its brilliant concept and design is surrounded by tons of money.
That’s how I see Java today. Just look at the number of communities, libraries and frameworks on GitHub, books, blogs and courses in order to understand that Java is a market leader. You can develop almost everything you want using Java: server-side app, client-side code, JVM database, programs for microcontrollers…
The Scala way
I like a quality stuff. That’s why when I hear something about Swiss cheese, watches, knives, chocolate and banks, I’m confident that people are talking about a high quality. As you may guess, Scala was developed in Switzerland. In 2004 Martin Odersky released the first version of a successful hybrid programming language. Why hybrid? Because Scala unites two worlds: an object oriented programming and a functional programming. If you have worked only with object oriented programming languages before, you would say, that’s a pretty weird mix.
Let’s consider what Scala gives to its users. First, you get all Java libs because Scala is compatible with Java. Secondly, a code becomes more concise and expressive, so you write less but get more. Finally, a concurrency in Scala is implemented in absolutely different level of abstraction comparing with Java. Sounds rather pretentious, doesn’t it? But that’s true.
This programming language has become a breath of fresh air for experienced Java developers who was exhausted with a boilerplate code, factory-delegator-facade patterns and a cumbersome enterprise development. Here is a list of Scala features, try to analyze it:
- Very concise syntax (helps to avoid a boilerplate code)
- REPL (try code samples in a console)
Optionclass (no need to use
- Functions as a smallest unit of code (no need to create a class where it’s redundant)
- Pattern matching
- OOP on steroids (case classes & traits)
- Powerful collections (3rd-party libs not required)
- Implicit arguments & values
Futureclass (asynchronous programming)
- Has all advantages of Java (except back compatibility)
If I missed something, please add it in comments, I’ll highly appreciate this.
A developer with all these features under the belt moves to the next programming level. Of course if the developer is ready to spend some time for understanding new concepts because Scala is harder than Java. Furthermore a learning curve can extremely vary from book to book and from tutorial to tutorial.
Talking about Scala disadvantages, I want to emphasize its complexity for beginners, absence of back compatibility and compile time.
Scala is still in a very active development. In this context its binary compatibility becomes an advantage because any unsuccessful experimental feature can be easily removed in the next release.
What about Scala financing? Well, on the one hand Scala continues its development due to the efforts of Ecole Polytechnique Fédérale de Lausanne (Scala Center), but on the other hand we know about Lightbend (formerly Typesafe). According to the CrunchBase information, overall investments in Lightbend make about $37M. Since “lightbenders” use Scala as a main programming language, I can say that Scala is in safe hands.
Also, I want to mention the companies and products where Scala is used: Twitter, Coursera, Foursquare, Apple (in some projects), Netflix, Tumblr, Walmart, Spark, Akka, Play! Framework, Lagom…
I don’t know what to add, Scala knows how to impress its users.
And the winner is…
I guess you remember that the title of the article is rather provocative. So it’s time to stop peaceful rhetoric and oppose Scala to Java 🙂
I don’t want to discuss banal things as compile time, learning curve and community size. All of us know that Java compiles faster, it’s easier to learn it and start to use it. Finally, number of Java developers is much higher than Scala devs. But what is interesting in all these boring questions? Scala knows how to resolve issues by continuous improvements.
So regarding the drawbacks mentioned above:
- New compiler is under development (Dotty promises high speed)
- Numerous books, courses and resources appear (choose anything what fits your needs)
- Scala community grows up (btw, in many cases it intersects with Java fans)
As you can see, Scala makes a good business, especially if we look at it in dynamic:
This diagram reflects the demand on Scala and Java developers. Please note that curves are relative, but not absolute. It means that total number of Java positions still exceed Scala positions. It’s easy to predict Scala progress in the future. Why? Because Scala totally satisfies its users and as a result – customers. Don’t forget about BigData world. Spark acquires total domination there. Reactive programming represented by Akka. Actually, I like this cosy company.
What about Java? Well, you know better than me, it still runs in millions apps and thousands of developers are looking forward to Java 9 with its so cool new features. Just imagine, Java wants to introduce JShell.
When it becomes possible, I will still choose Scala.
Also, be sure, I’m really happy that Java evolves because this process implicitly makes Scala better on JVM level 🙂