Tuesday, January 8, 2013

Distributed Encounters of the Scala Kind

"Parallel programming".
I never got to learn it in my undergrad. Sure, I studied multithreaded programming, but I never liked it much. There was something unappealing about it and to this day, I never even cared to find out what it was. But the first semester of my grad studies, when I was required to take at least three out of five core courses, I chose this course. Not really because I wanted to, but I had already chosen two courses which I was very much interested in, and of the remaining three courses, this was the most appealing. So, I chose to do Distributed Operating Systems Principles. I obviously never expected to take a liking for this course, but two weeks into the course, boy was I wrong!

We got introduced to the actor model and as someone new to distributed programming, I soon felt that this was one of the most practical and the most anthropomorphic design models that I have ever worked with. And it fit almost perfectly in distributed programming. Basically, it involves a set of entities called actors which can each receive messages. And when they receive a message, they can do one of these: send messages to other actors; create other actors; change their own way of responding to messages.
There are a bunch of programming languages out there which support actor model (http://en.wikipedia.org/wiki/Actor_model#Programming_with_Actors). But our course instructor introduced us to a relatively new programming language called Scala.
Having been built using JVM as a base, Scala is vey similar to Java. Actually not just similar, it can even inherit and use Java libraries. The level of abstraction in Scala is high and by high, I mean, huge. If you write a Java program of 100 lines of code, in the berst case, you can probably write the same program in maybe even 20 lines of code in Scala. That's the kind of abstraction I'm talking about.
Of course, there is a limit to how much abstraction you can introduce in a programming language and sometimes it can get too far. Check out http://metamatix.org/~ocaml/price-of-abstraction.html. This was a study done to determine the effects of abstraction on efficiency. And Scala seems to perform quite poorly in comparison to C++ due to its level of abstraction. But as they themselves say on the webpage, it is only in the most pessimistic situations that Scala performs this bad.
But having worked with Scala for the past six months, I have personally come to think it's probably the next big programming language out there. And here is why I think so:
  • For one thing, it is pretty easy to transition to Scala if you are a fairly good Java programmer. It reminds me of the way Java was influenced by C/C++.
  • It implements object oriented programming.
  • The high level of abstraction enables you to write compact and easy-to-understand codes.
  • This I think is the most important reason. With the importance of parallel programming on the rise, the easy-to-use features of Scala may convince many people to start using it. The grand trade-off between OOP and FP in Scala seems severely appealing.
This Is Sparta Meme - This is Scala!!!
But again, these are my personal opinions. Things might take a different turn in the future.
As for distributed programming, I have taken a big liking for it ever since I started working with Scala. It's easy to use and more importantly, it lets me implement my ideas the way I want them to be implemented.
It is no wonder that Twitter started using actor model through Scala. Probably the most comfortable factor for Twitter to use Scala is the fact that it limits tweets to 140 characters. And each time I run a distributed program on Scala and find actors passing messages between one another, it feels like they're tweeting, hehe.