I'm a software architect/consultant in Boulder, Colorado. I started blogging at: http://wayne-adams.blogspot.com/, but have since started the new blog, Data Sceintist in Training which will cover the areas I am learning as part of my own "big data" training, including the Hadoop family, frameworks like OpenStack, the R programming language, column-oriented databases and the art of examining data sets for useful patterns. The original blog will be kept alive with Java-specific posts. Wayne is a DZone MVB and is not an employee of DZone and has posted 35 posts at DZone. You can read more from them at their website. View Full User Profile

Day 4 - Scala

  • submit to reddit

Scala is the 4th language in Bruce Tate's Seven Languages in Seven Weeks. It is the only language in this book with which I am already familiar, although I've only been learning it for a month or so. Scala is interesting in that it runs on the Java virtual machine, a feature which may give it a leg up in the language race. I remember when I and my co-workers "discovered" object orientation. We studied Coad and Yourdon and prototyped in Smalltalk and C++. C++ was a great bridge to OO for C programmers, and it wasn't hard to tell from the beginning which language was going to win that race.

Of course, Clojure runs on the JVM also, so maybe this time the race will be a little more interesting. From my own point of view, the JVM connection definitely influenced my decision to start learning Scala rather than some other functional language.

Bruce covers a lot of material on Day 1, really too much to list here. As he points out, to explore Scala is to explore both a functional language and an object-oriented language. So Day 1 is a very dense race through many features of Scala.

Day 2 begins with a discussion of function definition, and a description of vals and vars, the general concept of mutability, and how important it is to pay attention to mutability if you are going to be a successful functional developer. As Bruce puts it, "mutable state limits concurrency." Think of all those IllegalStateExceptions and NullPointerExceptions in your multi-threaded Java code. If your application had no mutable state, it wouldn't matter how many times you called a method, or what you called before you called that method, or how many threads are calling the method. After years of being sent on-site to diagnose such problems, this is the reason I'm interested in functional programming.

Next, Bruce introduces Scala's collections, emphasizing Lists, Sets, and Maps. He then discusses higher-order functions (that is, functions which take functions as arguments and return functions), code blocks and anonymous functions. Following is a detailed enumeration of list operations. This is all preparation for Day 3, of course, which primarily covers XML processing and concurrent programming.

Scala's support for XML involves treating XML as a first-level language construct and providing query support similar to XPath. A couple of brief query examples are followed by a discussion of Scala pattern matching, including guard conditions and regular-expression support, and then a discussion of using pattern matching in XML processing. Day 3 ends with a quick discussion of Scala concurrency and a couple of examples.

As with all the languages, Bruce ends with a discussion of Scala's strengths and weaknesses. His discussion of the advantages and disadvantages of Scala's Java connection is worth reading even if you decide not to dive deep into Scala, or even dive deep into Bruce's "week with Scala." As with VHS and Betamax, it probably doesn't make sense to make any predictions at this point concerning what development paradigm and/or representative language will "win" in the developer marketplace. That's another reason why I like this book, or course -- it's a very thoughtful and non-trivial investigation of a variety of languages. And I didn't even have to choose which languages to investigate!

From http://wayne-adams.blogspot.com/2011/03/day-4-scala.html

Published at DZone with permission of Wayne Adams, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)