Java to Scala in the pursuit of Intention

This is a response to Cedric Beust's From Scala back to Java

Cedric linked to a very interesting discussion of the migration challenge from Java to Scala and the hurdles that are holding people back or pushing them away. This is an essential discussion to be having as migration is the reality for most companies and developers considering Scala. Very few of us have the luxury of starting fresh.

"This situation is pretty shameful, to be honest. Scala is about seven years old and the absence of decent IDE support after such a period of time is absolutely unforgiveable, especially given the ambitions of the Scala team." -Cedric Beust From Scala back to Java

That statement concerns me deeply. It is contradicted by my experience with IntelliJ IDEA's Scala Plug-in. I use this plugin every day for my work and I find it covers the subset of Scala that supports direct class-based object-oriented (Java-style) programming nearly as well as IntelliJ does Java. The support goes deep as well as it supports most of the refactoring and static analysis work flows IntelliJ provides for Java. JetBrains' Scala plug-in also gets very close to fully supporting the very complex combinations of Scala features that give rise to internal DSLs.

"First, I’m not sure that the envelope needs to be pushed any further in Scala. A lot of potential users are routinely turned off by its excessive functional and academic aspects and its complex type system. The interaction between functional and object oriented features already feels pretty complex to handle, so I certainly don’t want the language to evolve any further. I hope that future efforts will be oriented more toward the libraries and the tools than the language" -Cedric Beust From Scala back to Java

I see this as another deeply troubling misconception about Scala and abstraction complexity in general. I am ashamed to admit that I shared this concern and even posted to that effect on this blog historically. Object-orientation was a huge mind-shift and jump in abstraction power over structured programming. Early criticisms labeled it as overly complex and unmanageable for teams. It is undeniable now that OOP has paid massive dividends to its adopters. The size of the OOP community is a testament to how accessible it has proven to be. I think the same is true of a fusion of OOP and FP as provided in Scala.

Scala's complexity is not complicated. It is a well into which you willingly dip as deeply or as shallowly as you like to be productive. This is another way of looking at Martin's Scala Levels.

What if different developers have different depths they dip to? How does this affect readability among developers? It could easily affect readability if developers go beyond their depth, but the same applies to inner classes and interfaces, runtime annotations, generics and reflection in Java. Chances are, if your team is uncomfortable reading code using these features, then they are equally unlikely to use them effectively in Java and will write obscure or incomprehensible code when they use them. However, effective use of these features yields shorter, more readable code that more clearly expresses it intent.

Abstractions give developers more tools to clearly express their intentions. Java's abstractions clearly help. When it appears that they don't it is simply a case of ineffective or novice application. The same is true of Scala, but its power in expressing intent is substantially magnified by a much richer set of abstractions. Java has a deep well of abstractions and gives a great deal of power to developer. Scala has a much deeper well of abstractions and gives an order of magnitude more power than Java for expressing intent directly.

Clear expression of intent is absolutely central to maintainable code. Scala is worth the work of learning and the cost of training to make your team more effective. It is worth it because it gives your team a considerable advantage over Java in expressing intent which will dramatically reduce maintenance cost over time.

I strongly suggest migrating from Java to Scala in the pursuit of intention.