Scala – by a dummy

I started the second day by deciding to go Hands On for a day and attend some of the Labs sessions. The first session today was about Scala, it was unfortunately again riddled with some organizational problems. We were supposed to be doing a hands-on-lab, but there was no internet in the room in order to pick up the examples and slides, so we had to make do. The room was a blazing furnace when we started, but that got sorted out after a while luckily. By that time I had however gotten quite uncomfortable on the little foldout chair that I was sitting in, so it felt like going from rain to poor really.

The 2 presenters of this University session, Dick Wall and Bill Vennes, were however making the most of the situation. They dove straight into the code, but showed everything they were doing in the runtime environment of Scala. I had gotten that to run before, so I was to some extent just typing out all of the examples they were giving that were demonstrating. I must say, it’s a very interesting experience to be able to just type some lines of code, execute them and see what the result is. If you question what you’re doing, you just type it in “repl” and you see whether your thoughts were correct.

Unfortunately I can’t share 3 hours worth of presentation in one post, so I won’t even try. Let me just share some of the things I found interesting about Scala.

First off, Scala allows you to write code that is almost Java in syntax and then allows you to shorten and clean that based on whether you think it looks good enough. There are so many shorthand ways of doing thing that you can actually write really clean and concise code. You do have to get into the Scala mental model before you can do that comfortably though. You have to be able to read the various operators that Scala supports in order to judge that. Dick said that in his head he had words for each of the operators he used, so that he could mentally translate the code into sentences and then judge if the sentences read well. You will have some startup work to do, but it looks like getting your first code up and running as a solid Java Developer won’t take you more than a few days. I’ve heard varying opinions, but people generally seem to take somewhere between 1-3 months before they’re as productive as they were in Java.

Next, there are some pretty damned cool features in the language. A good example is the existence of traits, which basically allows a class to inherit from more than one other class. To call it traits really says it all, you can add multiple traits to a class and make it more and more functional. Good stuff! Another example is the enormous extension that the language offers to the Java-switch concept. You can do almost anything with the match-statement as Scala calls it. These features really seem to allow you to get more done in less time, so that’s a definite plus.

Conclusion
It appears that Scala brings a lot of power and allows you to write code that is more readable than Java code. It really enables you to write DRY-code, but also allows you to write code that is completely unreadable like some PERL programs I’ve seen. I find that to be both appealing and quite scary at the same time, so I’m still on the fence as to whether I really should start using Scala.

The best thing I took away from the session is that it’s quite possible to make a gradual switch and turn back if you don’t really like what you find. A good suggestion by the hosts was to start by writing Tests in Scala for production code that you write in Java. This allows for a trial period and allows you to stay out of production code. It’s also possible to write jar files in Scala and use them in Java. You would write your interfaces in Java and then implement those in Scala code. This would allow you to do only segments of a system in Scala and allow other places to stay in familiar old Java (or Groovy, or Jython, or whatever)

Advertisements
This entry was posted in development, devoxx. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s