Java vs. Scala : Why Scala?
Are you a Java programmer? do you use JVM a lot but still want to spend time with family and friends? It is probably time to learn Scala!
While the simplicity of the Java language has undoubtedly been a big part of its success, ironically, it has also contributed to its complexity. Needless to say, you can write nearly anything in Java, but the lines of code required to do so can be quite off-puting.
There is some truth to the statement « Scala is hard » due to its slightly more complex structure, but if you can write a somewhat complex single line of Scala that replaces a dozen “simpler” lines of Java, which one is really more complex?
Let us see, for example, these lines of code in Java vs. Scala:
Java:
Scala:
As I just said, all in one line!
It is clear that Scala is a kind of elite programming language. It inherited almost all strong advantages of JVM while being a functional language resulting in its impressive precision, comparing to Java which is often just way too verbose.
Scala makes clever use of several features such us Type inference, Function passing, Operator overloading, Future
class (asynchronous programming), Option
class (no need to use null
), Pattern matching and Implicit arguments and values. It also has all Java’s advantages (except backward compatibility) and much more. One of Scala’s most interesting features is built-in evaluation called “lazy”, which allows the language to defer time consuming computation until it is needed. In order to achieve this the keyword “lazy” is used within the programming code.
Although Java is evolving to embrace the advantages of a more functional style, Scala has still a lot features that Java does not have (yet) and it has a more compact syntax. This makes coding with Scala a lot more fun and productive.