You have probably heard that the Scala language combines functional and object-oriented programming; runs on the Java Virtual Machine (JVM), so it can leverage all the code written in Java; and has a good reputation for writing concurrent programs. How do you go about learning to program in this language? A quick search will turn up the standard guide [1] coauthored by the creator of the language, Martin Odersky, but this is an 800-plus-page tome. Is there no other way?
This new book by Horstmann might be the answer. It sports John Tenniel’s white rabbit illustration from Alice’s adventures in Wonderland, and is appropriately geared to those who feel they have no time to lose. The premise of the book is that you can teach a language by presenting it succinctly, requiring attention from your readers, and helping them digest the material by getting their hands dirty with code and online documentation. The chapters are short, and written in a fast-clipped style. This no-nonsense approach fits the book’s purpose well. The whole book can be read from cover to cover in a couple of days, but that alone will not make you a Scala programmer, of course. To grasp the book’s content firmly, and gain some experience in Scala programming, it is necessary to practice the material the author presents by doing the exercises at the end of each chapter. At some points, the author takes short excursions into the underlying workings of the language compiler, the JVM, and the rationale behind decisions in the language’s design. We could use more of these juicy bits. The book references Expert C programming, by Peter van den Linden [2]; Horstmann should have followed this example a bit further and devoted more space to exploring and explaining Scala’s intricacies. It turns out that there is a method to many of Scala’s complexities, namely, that of designing a language for growth [3]. This book could have given us more on that.
Horstmann presents a lot of information in 350 or so pages. He starts with four chapters on the basics: how to use Scala interactively, control structures and functions, arrays, and maps and tuples. He then moves on to classic object-oriented territory in the next four chapters, covering classes, objects, packages and imports, and inheritance. This is followed by six chapters on more advanced topics, including files, traits, operators, higher-order functions, collections, and pattern matching and Scala’s case classes. Really advanced material takes up the last third of the book, with chapters on annotations, Extensible Markup Language (XML) processing, type parameters, advanced types, parsing, actors, implicits, and delimited continuations.
There are some problems, which could be addressed in a future edition. Some of the cross-references are missing or wrong, or seem to be, in part because the reader is not alerted to the fact that some things are really explained in later chapters. Some basic Scala ideas are not included at all. For example, readers are strangely told that partial functions are instances of PartialFunction, but not that functions are really instances of related traits. Although delimited continuations, which can be used via a compiler plugin, are presented in some detail, there is only a passing reference to Akka actors, which are poised to replace the current library of actors.
Experienced programmers and advanced students who want to get a grip on Scala quickly will find the book just the tool for the job. Programmers that already know Scala will appreciate it as a good refresher.