This repository contains some sample solutions to the exercises in Cay Hortsmann's book Scala For The Impatient.
Like everything else, it is a work in progress. It contains progress to date noting that I haven't spent the time to create solutions for those exercises that either:
- don't really interest me - e.g. exercises for the chapters on packages and annotations
- exercises that don't readily allow test driven development - e.g. those that just want output printed to the console (albeit I've converted many of these to return testable Strings)
Is the code in the solutions any good? I very much doubt it! As a long term Java user (and previous user of many other imperative languages), I know that I haven't really got the many of the Scala idioms "down" yet. It is worth mentioning that despite having just completed Martin Odersky's course Functional Programming Principles In Scala, I am trying to create solution answers only using concepts introduced in the chapters preceding each exercise. So, for example, the early chapter solutions contain lots of mutable variables, explicit looping etc
The project can be built with SBT using the build.sbt file. This should bring down the dependencies for testing using ScalaTest and supporting running the tests as JUnits if required. Running "test" from sbt should run the 130 or so ScalaTest based tests which, at the time of writing, should all pass.
The repository doesn't include any Eclipse related files although Eclipse is being used during the development. The SBT eclipse plugin
can be added using
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
and then the project files created using
sbt eclipse
.
With Scala 2.10 released on 4th January 2013, I changed the build over to Scala 2.10. This required a few source level changes e.g.
- explicit imports now required for some of the less commonly used areas of Scala such as
scala.language.reflectiveCalls
- the 2.9.x Actor classes are deprecated in favour of the Akka framework with previous
scala.actors
code now moved out to a separate jar. This required changes to the build script.
The upshot of all this is that the project can no longer be built "as is" with Scala 2.9.x - it requires Scala 2.10
As a long term Subversion user, I am using this project to learn Git and GitHub. Apologies for any faux pas!
There are plenty of GitHub repositories that contain exercises for one or two chapters of Scala For The Impatient. Alexander Mikhailov's repository proved a more useful source of inspiration/ideas when stuck!