October 5, 2010

Getting Started with Scala - IDE support

The key thing when start using a new library or as in this blog, start writing a completely new language, is to have an IDE that is working with and not against you.

I had the pleasure of talking with both Martin Odersky and Jonas Bonér at JAOO in Aarhus Denmark and they both recommended the IntelliJ Scala plugin, but Martin also added that he had started a company scalasolutions.com with one of the aim to write a better Scala plugin for Eclipse, and when that comes out, I would really recommend you to test it. Another question which IDE to choose is also of course which IDE you have previously worked with and acquainted with.

In this blog I will share my experience of using both the IntelliJ and Eclipse IDE, but also how to build your Scala code with Maven.

IntelliJ
Since I don't have a business license of IntelliJ I used the Community edition, you can find the comparison matrix between the free and commercial edition and also the download link from.
http://www.jetbrains.com/idea/features/editions_comparison_matrix.html

After installing IntelliJ, you install the Scala plugin with the Plugin Manager

File | Settings | Plugins

Select tab Available and search for Scala, then right click to install.

After restarting, you create a new Java Module and add Scala Library from local downloaded Scala distro.

Experience
Plus:
  • Normal code completion and code navigation works.
  • OBS when debugging, you have to append the name mangling '$1' to every variable to be able to Evaluate. This seems a bug in the Plugin, since the name mangling should be shielded from you and is strict Scala internal, to overcome Java restriction of operating overloading, etc.
Minus
  • The IntelliJ Scala plugin compiler is really slow, even for small amount of code. There are ways to get around this by using Scala background compiler server, but I have not got that up and running yet.

Eclipse
I used the Eclipse 3.5.2 (Galileo) and install the Eclipse Scala plugin (http://www.scala-ide.org/) with the Eclipse built in Software Installation.

Help | Install New Software... | http://download.scala-ide.org/update-current Add

After that you can create a new Scala Eclipse Project.

Experience
Plus
  • The Scala Plugin compiles code enormous time faster compared with the IntelliJ, but it also have drawbacks.
  • Code completion is not always working if program Scala in it most compact form, sometime it then helps to program a little more verbose, e.g. anonymous function "kalOk".exists(char => char.isUpperCase) instead of the more compact "kalOk".exists(_.isUpperCase)
  • OBS when debugging, you have to append the name mangling '$1' to every variable to be able to Evaluate. This seems a bug in the Plugin, since the name mangling should be shielded from you and is strict Scala internal, to overcome Java restriction of operating overloading, etc.
Minus
  • Code completion is not always working.

Conclusion
After testing both IDE, I must say that Eclipse wins, and mostly because of the slow compilation in IntelliJ. But I hope even if you choose to use another IDE, that this blog post helped you with choosing which IDE you will use.

Maven
After choosen IDE, you clearly also want to have build tool support and I will here discuss Maven, but I also knew that SBT (http://code.google.com/p/simple-build-tool/) is also a great alternative, but I will not cover that in this blog.

The simplest way is to use the scala archetype, but before please check the page http://docs.codehaus.org/display/MAVENUSER/Archetypes+List, to see that not a newer version has been released.
$ mvn archetype:generate -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple -DarchetypeVersion=1.2 -DremoteRepositories=http://scala-tools.org/repo-releases -DgroupId=se.msc.example -DartifactId=scala-maven -Dversion=1.0-SNAPSHOT
To check that everything worked install the new Maven project.

Now lets open the new pom and see what has been generated. The first thing you see is that Scala 2.7.0 is used, change that to 2.8.0 but also remove the Scala Spec Test in

scala-maven/src/test/scala/se/msc/example/MySpec.scala

Finally you can also remove the specs dependency. I will in coming post discuss Scala Unit Testing, but for now simply use JUnit 4, that you are probably familiar with.

Thats it happy coding!

No comments: