Is Scala Complex? Yes ... and?

DZone 's Guide to

Is Scala Complex? Yes ... and?

· Java Zone ·
Free Resource

This article has been inspired by a thread that appeared on the Java Posse mailing list, that in turn was started as a comment to a blog post that tried to demonstrate how Scala could be less complex than Java.

In my opinion the provided example is too small and specific to be meaningful. It is not possible to generalize and infer a reliable comparison between two languages from such a trivial task, so it doesn't prove anything. At least as much as a Scala method declaration like:

def map[B, That](f: A => B)
(implicit bf: CanBuildFrom[Repr, B, That]): That

as discussed here, doesn't demonstrate that Scala is unbearably ununderstandable for mere mortals like us.

More generally, I think yes: Scala is more complex than Java. On the other side the same complexity is not vain since Scala derives its conciseness and power from it. I don't understand why people confuse conciseness with simplicity. Actually what is true is far more often the opposite: do more with less implies that the bigger thing you are doing in a lesser verbose way is achived with a more powerful and then more complex language.

To give an analogy, I remember one of the most difficult exam I did at university was theory of signals (I hope the translation of the exam's name from Italian is correct) and the book on which I studied hadn't more than 200 pages. In the same period my sister, who is a lawyer, was studying for an exam about ancient Roman right. She had 2 books with about 2000 pages each, but her exam went far more smoothly than mine. And I don't think (or I am too proud to admit :) ) that she is more intelligent than me. I hope it is clear what I mean to say.

So yes, Scala is less verbose and then more complex. And? Where is the problem with that? I am not scared of complexity and I think the biggest part of people doing our job aren't scared either. Actually I must admit I am fascinated by complexity, but of course I prefer when I can put my brain at work with a purpose. As with Scala: if I can trade simplicity with more power, less verbosity and in the end more productivity I am happy of that.

In the same mailing thread that I mentioned at the beginning of this article, Fabrizio Giudici pointed out that there are Java libraries like Lombok and lambdaj through which it is possible to make the Java code in the article that started this discussion almost as straightforward and concise as the Scala one. He underlined that a good Java developer should be aware of all the available tools and how to leverage them in order to make his job easier and more productive. I totally I agree with him, but unfortunately I cannot say the same when he said that the existence of these tools proves that Java has a "reasonable set of extension points to tailor it to people's needs". I don't know if that can be true for the wonderful project Lombok, but my personal experience as creator of lambdaj is not on the same page. I actually had to invent and implement literally tons of (sometimes awful) hacks and workarounds. And the final result of this effort is a library that works only on a (hopefully not small) subset of the cases I would had cover.

The current Java situation will probably get even worse with Java 7. I guess whoever is subscribed to the lambda-dev mailing list like me, or is following how the implementation of the new lambda expressions is coming along in some other ways, can easily understand, and possibly share, my fears. My personal opinion is that Java is going to become at least as complex as Scala but with only a small fraction of the Scala's expressiveness, power and conciseness. If that is true this is the worst scenario I can imagine: complexity + verbosity. This is the real unbearable complexity for me: the one that causes more problems than it solves.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}