Wednesday, July 30, 2008

A novice Scala programmer: Eclipse vs. IntelliJ IDEA vs. Netbeans. Creating and running Scala project with IntelliJ IDEA.

In a first post in this Scala mini series I described my experience with installation of Eclipse, IntelliJ IDEA, and Netbeans applications and installation of Scala plugins in those environments.
In a second post I explained how would I create, set up, run and debug Scala project in Eclipse.
Now, let's now follow the process of creating, configuring, running, and debugging a simple Scala project with IntelliJ IDEA. As a test project I will use the same "Rational" class defined in chapter three of the wonderful Programming in Scala book written by Martin Odersky, Lex Spoon, and Bill Venners.

V. A process of creation Scala application with Intellij IDEA plugin is slightly touched on IntelliJ IDEA Scala Plugin page and in corresponding forum.
1. Start IntelliJ IDEA. Use File | New | Project menu and create chp6Rational Scala project in an appropriate folder. Choose Project Name, Project File Location. Note, that
IntelliJ IDEA does not automatically create a project folder, so you would need to create chp6Rational (you name it) folder in your Scala work folder. Make sure you selected application type as Java Module. On a next screen check "Create Source Directory" and name it as "src". On a yet next screen, make sure that "Scala" check box is checked and a proper Scala SDK appears in a box to the right. Finish this long process.











2. Expand the "chp6Rational" project tree, select "src"folder, right click and choose New | Package. Name it "rational".



3. Expand the project tree, select "rational" package, right-click and choose New | Scala File. There are no predefined templates for Scala Object or Scala Class creation (you can add your own). Add an appropriate code from "Programming in Scala".


4. Save everything.


VI. Here's how to set, compile, run or debug Scala application with IntelliJ IDEA.

1.
Click on a small arrow-down button on a toolbar under Run menu to set up run configurations or use Run | Add new configuration / Edit configuration menu. Set application name and main Class name (PackageName.MainObjectName format). Hit "Run".
2. What really drives me crazy is the fact, you'll need to at least two mouse click every time you need to run your Scala application. Although system already remember settings from previous run, it asks you again.





3. Debugger works nicely with Scala application. You can set breakpoints by double-clicking white area to the left of your code, execute code line-by-line, see values of variables.
Hit debug button (right arrow) on a toolbar, confirm app settings and debug. You don't need to manually switch from "Debug perspective" to "Scala perspective" after you finish debugging, as you need with Eclipse.