Monday, August 10, 2009

Scala Columdrum

Man, I really want to love Scala:
  • It runs on the JVM and interacts well with Java.
  • It is statically typed. Despite dynamic language proponent's insistence that static typing is overrated, unit testing will catch all runtime type mismatches, etc., testing can only ensure the presence of bugs, not their absence. Compiler-flagged type enforcement can ensure the absence of this very narrow but prevalent class of error.
  • It has sensible type inference. The pain of static typing comes in all the boiler plate verbosity usually accompanying such a language, just to shove the compiler's face in it ('see this type??? here it is - remember it!'). Scala's type inference allows it to approach the brevity of dynamic languages such as Ruby, removing one of the biggest arguments against static typing.
  • It encourages immutability with val-ues as well as var-iables.
  • It provides a nice framework in the core library around concurrency modeled on Erlang's actor that should help you write efficient and, just as importantly, (more apt to be) correct multi-threaded applications. (See also this evaluation of actor concurrency, Scala, Erland and Java.)
  • It is fully object oriented but also a functional language, so you can be functional when you need to be ('to iterate is human, to recurse divine').
But I can't love it. In fact, in practice, I don't even think I like it.

Its 'Achilles Heel', at least for me, is syntactical in nature. You can basically name methods using any symbols you'd like, enabling operator overloading - sort of, actually 'operators' are all just method calls here - in addition to Perl-like tendencies toward self obfuscating code. Operator overloading was one of the many things I disliked about C++ and I don't like it any better 20 years later, even if the rules are at least consistent with Scala (anything can be a method call and "." and "()" are optional for single arg'd calls). The problem is that this is worse than just operator ambiguity, it's *anything* ambiguity. This and other syntax choices can and have resulted in a body of Scala source that is downright impenetrable. And this is directed at well-written Scala: I'd hate to see the bad stuff. Perhaps it's spelled out best here.

Scala is young but there are numerous high profile web applications starting to use it and a number of exciting frameworks are being built on its back, the Lift web framework being perhaps the most well known of the bunch.

Can I get past this syntactical annoyance? Sure. Might I have to? It's possible. We're still waiting for an alternate language running on the JVM to reach critical mass. But with the Oracle acquisition of Sun and thus ownership of Java the language, it's hard to say what will happen to it - nothing much for some time, obviously, given 14 year proliferation of Java-based applications the world over, but eventually. Even without Larry Ellison's imminent domination of our planet, the language is getting awfully bloated (the O'Reilly Nutshell book comes from a mighty big fuckin' nut!) and conversely is missing some essential ingredients, such as real closures. And it's just getting to be time for another to dominate. Given the large base of apps and the evolution of the JVM, I'm thinking something running on it has got the best chance (sorry, Rubyists).

Groovy's the most popular JVM alternative to Java to date, but it is, at its heart, a scripting language more than anything, good for that and for building some simple web applications. Not sure it fits as a server-side language, certainly not as the foundation for your platform or enterprise (if there is such a thing anymore).

So maybe I'll need to embrace my inner obfuscation one day and become a serious Scaladite (Scalapal-a? Scal-lad? Too sexist. Scalavocate?). Meanwhile, I'm holding out for something else. Of course, I wouldn't want my house to burn down.

No comments:

Post a Comment