Scala First Impressions

Over the mast month or so I've been studying the Scala programming language, and am about halfway through the bookProgramming in Scala, Odersky, Spoon and Venners.

My initial exposure to Scala was kind of double-edged. On one edge, attraction; the other, revulsion. All great technologies, works of art, areas of learning can have this duality. Obviously, these works initially attract me. From that set, many succeed in subsequently repelling me forever for one reason or another. Ruby succeeded in not repelling me forever. Only time will tell with Scala.

The initial attractions of Scala were through advocates. One who worked for Twitter, who showed some Scala code in his blog that replaced lower-performing Ruby on the Twitter platform. Another, Vladmir Kostyukov's ScalaCaster collection of data structures on Github, includes some code that implements the Quicksort algrorithm in about 20 lines.

What else constitutes attraction? Simon Peyton Jones (a principal researcher at Microsoft) has some thoughts on this regarding Haskell. "Nirvana" according to Jones, is where a language is both safe and useful. Scala, (although unmentioned in this video) resides in the upper-right hand corner of Peyton's chart. It's arrived to Nirvana prematurely. Scala code and methodology is alien to most of us. But it's friendly. Like a friendly Alien. It can be elegant and beautiful, and hides/eliminates a lot of programmer design work from plain sight by leveraging implicit behavior and functional design. (The latter being a core capability of the language.) Like Ruby, Scala crosses-into a higher threshold of legitimacy when well-written code becomes more or less self-documenting. Other languages simply cannot do this. Both Scala and Ruby can be written in concise and high-level manner, such that the design of good code can approach the special virtue of being correctly interpreted by a non-language-expert. In my mind, this shows exceptional thought placed into language design. An Alien that can communicate to common-folk.

So those are a couple of the major attractions. The revulsion side of the two-edged Scala sword is the complexity and steep learning curve. One of my biggest turnoffs when I was initially clueless about the language, was to try to make sense of it by reading a whitepaper overview of Scala. I managed to get about halfway through. Not exacly the most compelling piece of marketing material. Although improvements have been made to the appeal of the Scala website and documentation, it would be unfair to say the language is simple and easy to learn. It is not. It is a complex language, a kind of Ruby++0x. Scala itself is comparatively new and ambitious in design, attempting to bridge the gap between two (or possibly even three) disparate worlds: those of imperative programming, functional programming, and object-oriented programming.

Remember the original selling points of C++? It was designed to be a dual-purpose language, so users of C (procedural programming practitioners) could transition conveneintly and logically into object-oriented programming practitioners. The C++ package offered programmers the ability to use the language as conventional, procedural C, or as newer, object-oriented C++. One language, supporting two convertible methodologies. The procedural mode was played-up as "A better C" -- and it arguably was. Error messages were much better for one.

Scala is offering the same kind of deal to programmers. Essentially, the language is built atop the JVM, and almost suggests it's "A Better Java", although there are too many differences to make this claim. There are features here and there that clearly fill in the potholes of Java language design failures. For example, all Java primitive types (int, float, long, etc.) are first-class objects in Scala. There is no special disctinction between object String and primitive string. No "wrapper" classes to objectify something that is not an object. Like Ruby, everything is object-oriented.

The big pitfall to Scala adoption may be the ability of users to adopt. Java programmers may be technically ready to learn, but have a tendency to rubber-band back to Java after trodding on Alien turf, inventing sophisticated excuses to return to the Old Ways. Why do something new and unfamiliar when you can get paid the same to do things in the old, familiar way? Ruby programmers, on the other hand, may very well not be technically ready to handle some of the computer-sciency aspects of Scala but may also have a head-start with regard to familiar syntax and principles of elegance that Scala offers. I don't know how Haskell users respond to Scala. My guess would be a tendency to return to the procedural ways of Haskell?

In any case the Scala effort is ambitious, and although it faces many adoption problems of transitioning programmers across language cultures, there is nothing that would match the average business manager to recoil in horror at having their code-base change to something any of their programmers would have difficulty with. Why make business harder than it is? Sure, the language has a lot to offer. Perfect code (or something close to it) may be achievable. But we already have systems that work, and we can easily find programmers in the market to replace or augment those we already employ. Scala programmers are too rare and expensive. We would hurt ourselves by transitioning.

Here lies the big advantage in being an unemployed technical person. You can spend time learning something everyone else is too scared to learn or use. You can pick up the gauntlet, face the intellectual challenge and enjoy the ride to enlightenment.