Alex Saint Croix

So.  

My plan was to save myself a lot of headache involving the silly amount of list and coordinate manipulation I was starting to do, and switch to Scala.  Great idea, things are now moving pretty quickly.  However, the decision came with some serious side effects.  First, Scala takes a long time to compile.  Type inferencing comes at a cost, and the compiler has to make two separate sweeps to make sure it conforms with Java type erasures as well.  Scala’s platform contains a lot of classes, all of which must be loaded into the class loader at runtime.  The potential savings gained from having fewer lines of code somewhat offsets this, but I found that compiles were taking an unacceptably long time to run a continuous build.

Searching for good ways to perform unit testing in Scala led me to ScalaTest, and upon installing it I realized I needed to upgrade from Scala 2.8.x to 2.9.x, so I did that.  Or tried to. Strange “file not found” compiler errors led me to the discovery that Scala 2.9 doesn’t run on IntelliJ IDEA prior to version 10.5, so I ended up gutting and reinstalling IDEA from scratch as well.

Once I got through that minefield and got my simple tests running, I started digging into setting up the Fast Scala Compiler (fsc) server to run in the background.  I’ve had very limited success with this.  In order to actually get it running I had to configure it in IntelliJ, then run it, copy the line from the run dialogue window into Terminal, un-b0rk some of the whitespace in the command, and run the server from the command line.

For a long time I struggled against this, without success.  Eventually I took a break, took a walk, went to the local cupcake shop and contemplated the matter while scarfing down a pineapple upside down cupcake.  When I came back, I dug some more and found a more straightforward thread about setting up fsc in IntelliJ IDEA. Nick’s description of the process gave me an idea.

I took out the port number from the fsc configuration screen and it. Just. Worked.

So, now I’m happily using the fast scala compiler, running my build every 30 seconds or so, cranking out unit tests to define my core logic behavior, and rapidly catching up to my last Java milestone.

When you code in Scala in IntelliJ IDEA, and especially if you use a test driven method like I do, you will find yourself constantly, constantly wanting to run the app.  In order to speed up this test driven development process toward continuous integration, and save yourself a lot of repetitive typing, you can use scala scripts in IntelliJ to do that bit for you.  This will help you to minimize the time you spend loading up the scala console, importing your classes, and running your test code.

Setting up a Scala script in IntelliJ IDEA is simple.  Here’s how:

  1. Create a new file in your project.  Call it <InsertNameHere>.scala
  2. Add whatever you would normally type into the scala console.  For example, to run the simple game display example I posted earlier today, you’d enter the following:
    import com.some.package.GameDisplay;
    
    val d = new GameDisplay();
    d.start();
    
  3. That’s it!  Now you can skip the typing and run the app directly.  Just right click on the new .scala file in your project browser and select “Run”.  It will probably tell you that you need java.library.path added to your VM classpath, but once you’ve tried to run it you can configure the VM preferences for that.  For more information about how, read this handy guide on Setting up LWJGL in IntellJ IDEA.