Why Scala Is Interesting

Jul 12, 2010 15:51

As anyone who reads this blog knows, my favorite programming language is Haskell. I love functional programming, and Haskell is a great vehicle for pushing functional programming to its limits. However, I try to keep up with other up-and-coming languages, especially functional ones, so of course I've been aware of Scala ever since it came out. At the time, I took a cursory look at it and didn't like what I saw; there was too much syntactic sugar for my taste and the language seemed excessively complex. However, some people I respect like the language, so I've been giving it another look. My comments are not based on a comprehensive knowledge of the language, just what I've gleaned from a couple of weeks of reading and playing around. Nevertheless, I already know enough to state that Scala is an interesting language and worth learning, particularly if you're coming from a Haskell background. I've been using the "staircase book" (Programming In Scala by Odersky et al), which BTW is a very well-written book which I recommend wholeheartedly.

There are two reasons I might want to learn a new programming language. One is that the language is useful for practical programming in a way that my current favorite languages aren't, and the other is that the language has some interesting features that I haven't seen before (or at least, haven't seen implemented as well). Scala appears to fulfill both criteria.

From a practical standpoint, Scala runs on the JVM, it's fast, and using Scala I can do GUI programming, web programming (using the Lift framework), and program mobile devices (using Android, though I gather that it's not yet a trivial exercise to get Scala code running on Android). Scala appears to be far ahead of Haskell in all of these areas. I expect that Haskell will catch up eventually, but I'd like to write these kind of applications now.

From a theoretical standpoint, the appeal of Scala is the way that it combines functional and object-oriented programming in a statically-typed setting. This is not easy to do. It's easy to do in a dynamically-typed language (for instance, Lisp with CLOS), but static typing brings in a lot of complexity, notably with respect to subtyping and inheritance. Haskell can support some aspects of OOP (notably, using type classes and existential types), but I haven't seen OO-style inheritance modeled in Haskell, even though it's often quite useful. Scala has a very sophisticated OO system, with features like explicit sub- and supertype annotations, covariance and contravariance annotations, etc. which goes beyond what I've seen in other OO languages. In fact, Scala implements all of its functional features as objects, so calling it an object-functional language is less accurate than calling it an extremely powerful OO language.

I think of Scala as kind of an object-oriented dual to Haskell; it's a best-of-breed language for its paradigm. (I'm ignoring dependently-typed functional languages such as Agda/Coq/Epigram here; I know they exist but IMO they can't yet be considered general purpose programming languages.) Whether objects are a more fundamental construct than functions in a statically-typed setting is unclear to me. In dynamically-typed languages, you can get objects from functions (assuming functions are closures), or you can get functions from objects, so the two notions are interconvertible. Whether or not this is the case with static typing, I think it's interesting to have two languages approaching this question from two different directions. On the other hand, I learned about OO from Smalltalk, and I have to say that I've never seen a statically-typed OO language that had the elegance of the simple message-passing model of Smalltalk. On the other other hand, I would much rather write a large program in Scala than in Smalltalk. (Also, Scala has an Actors library for when you really want straight message-passing.)

Another thing I like about Scala, and one it shares with Haskell, is that both languages have their roots in academia. When you're designing a language with a sophisticated type system, it really helps a lot if you actually know something about type theory. Both the Scala and Haskell designers clearly do, and this accounts for many of the good qualities of these languages. I hope that we're soon approaching the day when the kind of people who dismiss languages because of their academic roots in favor of real he-men "practical" languages will have to STFU because the evidence will show that languages designed by academics (i.e. people who actually know what they are doing) are simply superior at solving real-world problems.

I'm still getting my feet wet with Scala, and I look forward to learning more. But I still love Haskell and I'm not going to give it up either ;-)
Previous post Next post
Up