But recently I still introduced it in our project. Not only that, but the team had no experience with Scala. I’ll try to explain why that is not a bad idea.
- First and most important – I followed my own advice and introduced it only in a small, side module. We didn’t have acceptance tests and we desperately needed some, so the JBehave test module was a good candidate for a Scala project.
- Test code is somewhat different from “regular” code – it is okay to be less consistent, more “sketchy”, and to have hacks. On the other hand it could benefit from the expressiveness and lesser verbosity of Scala, as tests are generally tough to read, especially in their setup phase. So Scala seems like a good choice – you can quickly write concise test code without worrying too much that you are shooting yourself in the foot in the long term, or that multiple team members do things in a different way (as Scala generously allows). Also, in tests you don’t have to face a whole stack of frameworks and therefore – all the language concepts at once (like implicits, partial functions, case objects, currying, etc.)
- I didn’t choose a scripting language (or Groovy in particular), because I have a strong preference for statically typed languages (yeah, I know Groovy has had that option for a couple of years now). It should’ve been a JVM language, because we’d want to reuse some common libraries of ours.
- It is good for people to learn new programming languages every now and then, as it widens their perspective even if that doesn’t change their language of choice.
- Learning Scala I think can lead to a better understanding and use of Java 8 lambdas, as in Scala you can experience them “in their natural habitat”.
As a side-note – IntelliJ scala support is now better than last time I used it, unlike the Eclipse-based Scala IDE, which is still broken.
If writing acceptance test code with Scala turns out to be as easy as I imagine it, then it can mean we’ll have more and better acceptance tests, which is the actual goal, and it would mean we are using the right tool for the job, rather than a hammer.