I haven’t started programming Scala in earnest yet, though I’ve been going through some books and typed a bit into the interpreter. (Whee, JVM startup times.) I had the Odersky book recommended to me, but I actually first read the PragProg book: I’ve had good luck with some of their books recently, it’s quite a bit shorter, and there is a tradition of excellent short introductions to programming languages in the field. I won’t exactly say I regret that choice, but the PragProg book isn’t anything special; I’m only 85 pages into the Odersky book, but I’m enjoying it quite a bit more.

A few things that amuse me so far, as a C++ fan:

Yet another book which has to explain that a variable being immutable doesn’t mean that the object it’s pointing to is immutable (just that you can’t reassign the variable to point to something else), and that there’s in fact no way to create immutable objects (assuming that the class allows mutation at all, of course). Is C++ really the only language that has a reasonable story about this?

Admittedly, C++’s story is far from perfect as well: all you have to do is hold a member variable via a pointer and then it’s up to the class implementor to declare const methods honestly, the compiler won’t have your back for you in that case. And that also points at C++’s main advantage in this area, that you can have variables that aren’t held via pointers: maybe without that, automatically enforcing constness is impossible, and without that there’s no benefit in letting class implementers declare which methods are const? I’ll have to think about that one; still, it’s certainly not an area that I would have thought C++ would be relatively unique in when I first ran into the language.

And after reading so many complaints about how you can’t tell what “a + b” means in C++ code, it’s great to see another language that unabashedly embraces operator overloading. And having operators that end in a colon be magically reversed to be methods of the object on their right is simply brilliant: not only does it naturally handle the cons case of

1 :: List(2,3)

but having /: be an alias for foldLeft is just brilliant: I think writing

(0 /: list) { _ + _ }

to sum the elements of list is super natural, much more so than a syntax with 0 and list reversed would be. (Think of it as smooshing down list starting with 0 at the front and with the function argument telling you how to do the smooshing.)

So yeah, Scala and I are going to get along just fine, I think.

Post Revisions:

This post has not been revised since publication.