First Impression of Scala

2014-07-18 18:34 +09:00
Lausanne, Switzerland, where Scala was born from.
Lausanne, Switzerland, where Scala was born from.

I’m a big fan of JavaScript, which I’ve used for 5 years since I first learned it. I’ve been using JavaScript for from small toy projects to serious business projects. Actually I still think that it’s a wonderful language and has a great platform like Node.js. I also love its functional language concept and open-source environment.

Recently, I got a change to do a project with Scala. In short, Scala is an object-oriented functional language. The official website also says that

Object-Oriented Meets Functional

and while learning it, I could find the meaning. Grammatically, it provides several tools to deal with object-oriented language concepts like inheritance or polymorphism. Scala is also a functional language as function is first-class object in the language and it has some key concepts used in other popular functional languages.

I should make it clear that I’m not an expert in Scala and just started it. So this article is the first impression from a Scala beginner who usually spent his time with script languages such as JavaScript or Python.

Scala the enjoyable parts

First of all, I’d like to say that it’s really enjoyable to write code in Scala.

When coding with JavaScript, I sometimes found that some important features are missing in it(which are usually supported by 3rd party libraries like Underscore), and if I want to do object-oriented things, it also can be a big pain in JavaScript because we should understand not only a grammar, but also an underlying prototype system. I don’t even need to talk about a bunch of callbacks which I should encounter in almost every code. These things can be very subtle, but annoying.

In Scala, I can escape from these things. I can’t say it’s perfect, but until now I found it was fine. Especially, concerning concurrency, I’m happy to use Futures and Promises. I think it’s a quite elegant way to deal with concurrency. Also I really like the pattern matching and list manipulating in it. Surely they’re quite common features also in other functional languages, but they sometimes don’t seem very familiar(LISP and Haskell fans won’t agree with this, though). I think that Scala has a good grammar about the functional features, maybe because ‘functional’ is not compulsory in Scala. We’re totally free to choose between the functional way and a conventional way.

With Scala, I can easily think that language features are helping me. It seems rightful that programming languages help developers, but sometimes they really don’t(I’d not like to suggest an examphple).

Meh…

I also found something not very perfect for me.

Different from JavaScript or Python which I’ve been used to, Scala is a static-typed language and provides type safety. I also did some projects with C++, but I admit that I’m very bad at prototyping with a static-typed language. So at first I started to use Scala, it was quite difficult to prototype something with it. The compiler always said there was a type error in the code. I know the type safety is a good thing, especially for a big serious project, but it seems that it takes a while for me to get accustomed to it.

Also I’d like to say about resources. I think Scala itself and its modules have good documentations, usually provided with Scaladoc. However when I want to find a method of String object, I should find a Java document, not a Scala one, because Scala uses java.lang.String for its String type. For sure, pure Scala types like List are in the Scala document. I felt it’s quite annoying to find one language’s reference in two sources.

Finally, concerning its language environment, I think it should be a bit neater. For example, when I want to handle JSON or DateTime, there are plenty of modules about them including Java modules, pure Scala modules and just Scala wrappers of Java modules, but it’s difficult to choose one. Some of them even don’t have a good webpage to introduce themselves. I don’t mean that every module needs a neat website, but at least it can help developers to find some reliable information.

Anyway,

I’m really enjoying writing code in Scala and the shortcomings would be settled down when I get accustomed to it. I think Scala is quite new and in addition to the current environment, a lot of good things will be made in the future. I hope I can find more enjoyable parts in the language from now.

read other posts