Wednesday, March 18, 2009

Scala Gets My Vote

Of all the languages I've read about recently, Scala strikes me as the one I'd most like to use.

I've always been interested in (computer) languages. I haven't actually seriously used many different languages - mainly C, C++, and recently Java. But I've avidly read about many.

I have books on Scheme, Smalltalk, Perl, Python, Icon, Dylan, C, C++, C#, Tcl, Ruby, Java, Lua, JavaScript, Erlang, Groovy, Scala, and probably more that I've forgotten.

I'm just finishing reading Programming in Scala by Martin Odersky (the creator of the language), Lex Spoon, and Bill Venners. Part of what prompted me to read it was a podcast with Bill Venners talking about why he likes Scala.

I liked C++. People criticize it because it was too complex, but I liked it's powerful features.

I can't get excited about Java. It's ok, and it has great IDE support, but it's a little boring. I like the garbage collection and the safety of no pointers, but I miss C++'s tricks with things like templates and operator overloading.

For some reason I haven't got too excited about Ruby either. I haven't written much code in it, but I've read a fair bit, gone to conferences, and managed a project written with Rails.

Ironically, Java compared to C++ is a bit like Suneido compared to Ruby. Both Java and Suneido try to avoid features that, although powerful, allow you to "shoot yourself in the foot" (if not in the head!)

Scala feels more like C++, lots of power and flexibility and tricks, enough to probably make your head hurt.

Both Scala and C++ try to support writing powerful, natural libraries and extensions, which I like.

For "system" programming (as opposed to "application" programming) I still lean towards static typing. But I do get tired of the verbosity of type declarations in C++ and Java. Scala is statically typed, but it also does type inference which greatly reduces the verbosity.

And it's a plus for me that Scala runs on the JVM and can be easily integrated with Java. (There's a .Net version as well, although not as well supported.) It seems like I could write parts of jSuneido in Scala if I wanted. I suspect you still might want to implement performance bottlenecks in Java, though. Or at least be careful which Scala features you used, since power often comes at a price.

Scala supports functional programming, but in combination with more conventional object-oriented programming. I haven't spent the time to wrap my head around "pure" functional languages like Haskell or (O(Ca))ML. But I could see using some functional programming in Scala.

I thought the Programming Scala book itself was good. It's not small - 2.6 lbs and 776 pages, but I had no trouble getting through it. I see it won a Jolt Award. Apress also has a Scala book, and both Pragmatic and O'Reilly have Scala books coming.


Don Stewart said...

> haven't spent the time to wrap my head around "pure" functional languages like Haskell or (O(Ca))ML

"Purely functional" doesn't mean what you think it does. It doesn't mean "very functional"

It means - basically - that side effects are ruled out by default. Haskell is a pure(ly) functional language. OCaml and the other MLs are not.

James Iry said...

Yeah, what Dons said. Scala sits, very roughly, about in the same space that OCaml does (although they are very different languages with very different strengths and weaknesses).

I would advise some care in how people read your comparison of Scala to C++. Scala's formal grammar fits in 250 lines of EBNF, the best attempts at writing an EBNF grammar for C++ get to about 1200 lines. C++ tries to take a high level approach to abstraction but sits it on a low level approach to memory management, Scala is garbage collected. C++ has special case after special case that interact in ways that only a language lawyer could love, Scala mostly tries to give power using a relatively few general purpose constructs.

For what it's worth, Haskell'98 is a simpler language than Scala, but once you "get it" it's astoundingly powerful. It's well worth learning. Perhaps once you're comfortable with Scala you'll find it a little easier to grasp. It's worth it - It'll make you a better programmer no matter what languages you end up using.

Welcome to Scala. Come visit the mailing lists and IRC channel.

andrew said...

Thanks for the comments.

I didn't mean Scala was literally like C++. Just that it had a similar "feel" to me. And I meant that in a positive way - I like C++.

I can't promise to really learn Haskell, but I can promise to read Don's book :-)

Jem said...

The Apress book is by David Pollak, author of the Lift web framework which is gaining some traction and looks quite promising. His blog is at There is a general scala blog at