In this blog, I ponder why Ruby and Scala are easy to learn and complex to master, and how their cultures differ. ♦

The Lunar new year has passed, and a new semester has started at Ho Chi Minh City University of Technology, where I am spending my sabbatical . Last semester, I taught the standard undergraduate programming languages course, mostly using Scala. This semester, I teach a second course that is not required, so I can do any fun stuff I want. 

I am using Bruce Tate's excellent Seven Languages in Seven Weeks book for guidance (which I recommend highly). But I am deemphasizing syntax even more than Bruce does, and I diverge from his treatment by choosing some topics and languages that are more academic/cutting edge.

We started with Ruby, just as Bruce does. Why Ruby? It's an easy sale because of Rails.

For someone who knows Java and some functional programming (whether from Scala, Scheme, ML, or whatever), Ruby is pretty easy to learn. I was able to cover the basics in one lecture.

  • Duck typing
  • No braces but Algol-style if/loops/function definitions
  • Blocks
  • Arrays and hashes
  • Miscellaneous function stuff: optional (), optional return, varargs, named and default parameters
  • Class stuff: instance variables have @,attr_accessor,initialize,self

That's enough to be dangerous productive.

Then I prepared my lecture on metaprogramming, and I quickly said “holy cow!”. There are a dozen ways of doing the same thing slightly differently, and I was soon in a fog of mind-numbing detail and sample code that looked like random line noise. It took me a long time to pick a subset of the features that made this example work the way I wanted to.

That made me think about Scala. Why is it that Ruby walks on water but Scala tends to get a bad rapfor complexity?

It's a little difficult for me to make an exact comparison because Ruby doesn't even have a language reference manual, but it seems to me that Ruby and Scala are pretty comparable in their “complexity budget”. Ruby spends it on an intricate metaobject protocol, Scala on an intricate type system.

I went back to last semester's slides to review my Scala crash course, and it wasn't all that different:

  • var/val/def
  • Types after names
  • Anonymous functions
  • Arrays, lists, and maps
  • Miscellaneous syntax stuff: optional (), optional;
  • Class stuff: Fields give rise to getters/setters, primary and auxiliary constructors

And yes, that's enough to make you productive in Scala. You can merrily code along and use other people's libraries. Of course, you won't necessarily understand how they work under the hood, but then again, how many Rails users really know what makes ActiveRecord tick?

However, I sensed a significant difference in theculture of the Ruby and Scala crowd, at least as evidenced in the blog posts. The Ruby afficionados seem like a bunch of wizards trading spells. “Hey, try this one, it worked wonders for me!” The Scala discussions remind me of a faculty commons room, where everyone wants to show that they are the smartest one. “Well, if you would just take the monadic point of view, it would be obvious that...”

I exaggerate, of course, and I am glad that Scala attracts the smartest ones who, after all, build the stuff that we all get to use without knowing how it really works.