Should I study Scala?

rpg picture rpg · Jul 10, 2009 · Viewed 8.6k times · Source

I am an experienced C++ programmer with average Python skills. The reasons I studied Python in the first place were:

  • to get a different perspective on programming (static vs dynamic, interpreted vs compiled, etc.)
  • to increase the breadth of projects that I can work on (Python allows me to do web development, develop for Symbian phones or knock up quick system administration scripts)
  • to complement my C++ skills.

I think that Python is great and I believe that I have achieved the above goals. I will continue to use it for small projects, scripts and web development.

I doubt that I can use it for medium to large projects though. While the dynamic typing is convenient, it allows a certain class of bugs that I find disturbing. Unit testing and linting can alleviate this problem, but static typing completely eliminates it.

After looking at some programming languages, I think that Scala looks like a good candidate: I like the type inference and it runs on the JVM so it should be available wherever the JVM is available. I can also learn more about functional programming when using it.

But... I also have some doubts, and this is where I hope that the Stack Overflow community can help:

  • Portability: Linux and Windows at least I hope. What about mobile phones, is it possible to get it to run there?
  • C++ compatibility: can I mix C++ code with Scala? (JNI?)
  • Programming paradigm: I don't feel comfortable with switching to functional programming (FP) at this time. Can I use object oriented and procedural with some FP at first and then change the proportions as I learn?
  • Tool chain maturity: what's your experience with IDEs and debuggers? I'm using Eclipse right now and it seems OK.
  • Learning speed: considering my experience, how fast do you think that I can reach a workable level with Scala?
  • Deployment: how exactly do you deploy a Scala program? Is it a jar, is it an executable?

Finally, what do you think that are some of Scalas disadvantages?

Answer

Daniel C. Sobral picture Daniel C. Sobral · Jul 10, 2009
  • Portability: Linux and Windows at least I hope. What about mobile phones, did anyone succeed in getting it to run there?

Yes. There is quite some movement about Scala on Android. As for J2ME, I saw something in that respect, but not much. There is some code pertaining to J2ME on the source code repository. I'm not sure how viable it is, but it looks to me that there isn't much demand for that.

I'll also mention that there is/was a pool on Scala-Lang about the desired target platforms, and J2ME was one of them, very low on the totem pole.

  • C++ compatibility: can I mix C++ code with Scala? (JNI?)

As well as you can mix C++ with Java, for whatever that is worth. If you haven't any experience with that, you can just read the Java resources, as anything in them will be applicable with Scala with no changes (aside Scala syntax).

  • Programming paradigm: I don't feel comfortable with switching to FP at this time. Can I use OO and procedural with some FP at first and then change the proportions as I learn?

Definitely, yes. Scala goes out of it's way to make sure you don't need to program in a functional style. This is the main criticism of Scala from functional folks, as a matter of fact: some do not consider a language functional unless it forces the programmer to write in functional style.

Anyway, you can go right on doing things your way. My bet, though, is that you'll pick up functional habits without even realizing they are functional.

Perhaps you can look at the Matrices series in my own blog about writing a Matrix class. Even though it looks like standard OO code, it is, in fact, very functional.

  • Tool chain maturity: what's your experience with IDEs and debuggers? I'm using Eclipse right now and it seems ok.

IDEA (IntelliJ), NetBeans and Eclipse all have good support for Scala. It seems IDEA's is the best, and NetBeans/Eclipse keep frog-jumping each other, though NetBeans has certainly been more stable than Eclipse of late. On the other hand, the support on Eclipse is taking a very promising route that should produce results in the next 6 months or so -- it's just that it's a bumping route. :-)

Some interesting signs of Scala tooling for these enviroments is the fact that the Eclipse plugin in development uses AOP to merge more seamlessly with the whole IDE, that the NetBeans plugin is being completely rewritten in Scala, and that there's a Scala Power Pack on IDEA that supports, among other things, translating Java code into Scala code.

The EMACS folks have extensive tools for Scala as well, and lots of smaller editors have support for it too. I'm very comfortable with jEdit's support for small programs and scripts, for instance.

There is also good Maven support -- in fact, the standard way to install Lift is to install maven, and then build a Lift archetype. That will pull in an appropriate Scala version. There's an scala:cc target that will do triggered recompilation as well.

Speaking of recompilation, neither Maven, and particularly nor Ant do a good job at identifying what needs to be recompiled. From that problem sprung SBT (Simple Build Tool), written in Scala, which solves that problem through the use of Scala compiler plugin. SBT uses the same project layout as Maven, as well as Maven/Ivy repositories, but project configurations are done in Scala code instead of XML -- with support for Maven/Ivy configuration files as well.

  • Learning speed: considering my experience, how fast do you think that I can reach a workable level with Scala?

Very fast. As a purely OO language, Scala already introduces some nice features, comparable to some stuff that's present in C++ but not Java, though they work in different fashion. In that respect, once you realize what such features are for and relate them to C++ stuff, you'll be much ahead of Java programmers, as you'll already know what to do with them.

  • Deployment: how exactly do you deploy a Scala program? Is it a jar, is it an executable?

The same thing as Java. You can deploy JARs, WARs, or any other of Java targets, because the scala compiler generate class files. In fact, you use Java's jar to generate a Scala's JAR file from the class files, and the Maven targets for Lift support building WAR files.

There is an alternative for script files, though. You can call "scala" to run Scala source code directly, similar to a Perl of Shell script. It can also be done on Windows. However, even with the use of a compilation daemon to speed up execution, start up times are slow enough that effective use of Scala in a heavy scripting environment needs something like Nailgun.

As for Scala's disadvantages, take a look at my answer (and other's) in this Stack Overflow question.