Don’t have any arguments in some cases?

Here’s the problem I recently encountered:

abstract class CaseClass

case class NoArgs extends CaseClass{

def tryIt(arg: CaseClass) = arg match {
    case NoArgs => true

What would you expect? I expected it to work. But I got a compiler error:

error: pattern type is incompatible with expected type;
found   : object NoArgs
required: CaseClass

Well, solution is easy. Just add the parenthesis to the constructor. Looks shitty but that’s how it – obviously – should be, given it’s not an object.

abstract class CaseClass

case class NoArgs extends CaseClass{

def tryIt(arg: CaseClass) = arg match {
    case NoArgs() => true

ScalaTest with IntelliJ

I just had a couple of problems with IntelliJ and ScalaTest. Under some circumstances, some of the tests didn’t run anymore. I had the problems some times before, but didn’t find anything helpful in the net, yet. I was really going crazy about this, ’cause nothing seems to help. Well I managed to get around it. Sadly without knowing exactly what the problem was. I just creating a completely new project in IntelliJ (project file format .idea (standard) and ‘Java’ not ‘Plugin‘..) copied the sources over to the new one, re-init of maven, and now it seems to work.

I played around with the project structure before the re-init. Might have caused some problems. Hoping everything stays fine now.

Choosing the IDE(A)

For me using an IDE is essential to work efficient. Remembering the time when the IDE’s were better editors is like thinking of my first time: It was feasible, but not fun, exhausting and I thought it was OK. Nowadays I know better: It is really fun if you know how and have the right one.

First of all let me say which features of an IDE are most important to me, then I’ll give you a highly opinionated overview why I’ve chosen the IDEA.

A good auto-completion also showing docs

  • Smooth navigation through the code and files
  • Good integration of third-party tools (in my case Maven and ScalaTest)
  • Overall ease of use and install

1. NetBeans

I started developing Scala with NetBeans (v6.8). Auto-completion wasn’t a dream, but I could use the environment I do best known and use Maven for builds. It started getting a little awkward when I started using ScalaTest. Well it was working. There was a good test runner from ScalaTest itself and how to include it without using Maven ist described here: Furthermore there is a JUnit test runner for ScalaTest, that can be used within NB with an (ugly) annotation.

Then NetBeans 6.9 came out. There were 2 Problems with 6.9:

  1. I got used to it quickly using it in my company and the Java parts I was working on in my private project.
  2. The Scala Plugin didn’t work in the first place.

So I started looking for an alternative…

2. Scala IDE (Eclipse)

Next I gave the Scala IDE (Eclipse) a try. Name is promising, isn’t it? Well I was pretty disappointed quickly. Good things first: Installation is easy. Auto-completion is quite good and navigation was OK too. For the cons an own paragraph:

The IDE comes with an own distribution of Scala and – for me at least – it was not straight forward to change it to the actual one. Furthermore I had several bugs with the run configurations. No real showstopper but things that are annoying when coming back again and again. As I want to use Maven at some point I had a look in the Manuals for the ability the Plugin to use Maven. Well to keep it short, its possible but not as easy as I like it.

One more – for me important – thing:

The look and feel. I don’t like the eclipse one any more. Its kind of ugly and bumpy. For me NetBeans is still the nicest and cleanest IDE. IntelliJ is OK, but Eclipse. Sorry guys. I know you are doing a great job providing this Framework for free for years now. But if you ask me: IT NEEDS A MAJOR FACELIFT….

3. IntelliJ IDEA

At that time I was starting getting annoyed by Eclipse, the JetBrain guys decided to free and open source a community edition of IntelliJ (thank you so much guys). Some of my colleagues were using it already and they have been quite impressed. So I thought: Let’s have a look if the community edition has a Scala feature too. Well, it has! And it’s great! Easy to install, use. The Maven support is good. Not as nice as it is in NetBeans. But auto-completion for the POM is working well, that’s probably most important.

Where there’s light there is shadow. Here are the cons:

  • annoying, f…ing long compile time (c.f. paragraph below)
  • often unable to infer the type of a variable for auto completion of  members

A good how to you’ll find here:

How to reduce this annoying compile time in the IDEA

Really simple if you know how. Make a new run config “Scala Compile Server”, give it a name e.g. “the magic server” or something you like, uncheck the make option (mui importante), and then run, baby, run…

Dunno if it really works. It sometime exits with some error exit code. But compilation overall feels faster now. And nothing else matters… 😉

BTW I’m working on OS X.