Thursday, September 18, 2014

Learning Scala via unit tests

Last month I followed a big data training session, and we used Scala to write algorithms for Spark. I had looked at Scala some years ago but I think at the time the Eclipse support wasn't very good (the pot calling the kettle black, eh?), and it piqued my curiosity again. So I started looking at tutorials, and found Scala Labs. The idea is interesting: you get a project with sources and tests, and you need to make all the tests pass. The source code for both the code to change and the unit tests is heavily documented, and guides you through the language nicely. And seeing the green ticks appear always triggers the proper reward areas of my brain (-:

I had a little issue getting the code to compile using Eclipse, since there's a sbt-launch-0.13.0.jar library at the root of the project, and Eclipse used that as the top library, and it had a weird version of the List class, that wasn't genericized! I removed that jar from the class path and everything worked fine.

I'm not aware of a similar tutorial for Haskell, but that would be a good idea!

1 comment:

CessationOfTime said...

The sbt-launch jar isn't usually kept inside the project. SBT is usually installed as an app to your OS. And then you can use an SBT plugin called sbteclipse to generate an Eclipse project based on the SBT settings of your project and import it as an existing Eclipse project.

Scala is the only language I like more than Haskell (Rust might be nice though). It's primarily because the ecosystem and tools feel much more developed. But I'm sure thats because they are able to easily rely on the entire Java ecosystem. Whenever I look at the EclipseFP code I'm always a little disappointed it is Java and not Scala. Though that would be less of a thing with Java 8.