Making the Climb Part 4–Pattern Matching

Continuing our journey down the path from the familiar to the down-right bizarre, we find ourselves at Pattern Matching. This is a feature of the Scala language that shows it’s functional side in a strong way. Pattern Matching is a fundamental part of functional languages in general, and provides a way to write very concise and expressive code. On the surface, pattern matching in Scala looks an awful lot like switch statements in C# (and Java for that matter), but you shouldn’t cling too hard to that association. ...

22 January 2012 · 7 min

Making the Climb Part 3 - Generics of a Higher Kind

This is part 3 in a series. If you’ve not followed-along so far, you may want to check out Part 1 and Part 2 first. It’s time to start digging in to some of the crazy-goodness that makes Scala such a glorious and wonderful thing. First things first, though, we have to talk a little bit about this history of Generics in Java and the JVM. Type Erasure and you… Back around the time that .Net was adding support for generics, the folks in Java land were doing the same…sort of. The biggest difference between the way Generics were implemented in .Net and Java is the fact that in .Net generics are supported directly in the CLR (sometimes called reified generics), whereas the JVM did not include direct support for generics. Ok, so what does that actually mean? Well, for starters it means that when you’re dealing with Generics in Java you run into Type Erasure. Type Erasure means that when Java code with generics are compiled, the generic type information is removed at compile time, so while you’re looking at an ArrayList in Java, the JVM sees this as just an ArrayList, and things get cast as needed. There are a couple of types which get reified into actual types (Arrays are the best example), but for the most part this doesn’t happen. In contrast in the .Net world a List gets compiled into a List`1<System.String> which is a real type at the IL level. Now, I’m not going to get into the argument about whether or not type erasure is good or bad, but it is a fundamental difference between the two platforms. ...

5 October 2011 · 8 min

Making the Climb Part 2–Object-Oriented Programming in Scala

In Part 2 of this series we’re going to move into some of the object-oriented aspects of Scala. For a primer on what Scala is, and a quick primer on syntax, check out part 1. Let’s start with the built-in object structure Like C# and Java, Scala has a built-in object hierarchy, and a standard library full of goodies. Unlike Java and C#, Scala tackled the issue of reference types and value types head-on, so while the root type in the Scala type system is the Any type, there are two descendants of Any that come into play before any other type. The two are: AnyRef, and AnyVal. As you might guess AnyRef is the base type for all reference types (including types made available from Java), and AnyVal is the base type for all value types. This is a little bit like the class and struct type constraints in C#, only you can use these as variables. They can also be used to limit type parameters, but Scala Generics are going to have to get their own post. ...

14 August 2011 · 7 min

Making The Climb: Head-To-Head with Project Euler (questions #1 & #2)

I’m going to take a brief intermission in my Scala series, and show a head-to-head comparison of some code in Scala and C#. To do this, I’m going to go with the first and second problems from Project Euler. If your not familiar with the site, it’s a playground full of problems that are absolutely perfect for functional languages (cause they tend to be mathematical functions). So let’s get started with Question #1: ...

4 August 2011 · 5 min

Making the Climb: Chronicling the journey from C# to Scala

Hows that for a title, eh? Yeah, I know, not great, but there is only so much creativity I can manage in a day, and as you will soon find out my mind is busy with all kinds of new and interesting thing, so any spare neural pathways which may have one been useful for something like clever titles are now just too busy to be bothered. So what is this all about? Several months ago I had an interesting experience. One that I could almost compare to a religious experience, only not quite so….religious. It started with the most excellent book [Seven Languages in Seven Weeks](http://pragprog.com/book/btlang/seven-languages-in-seven-weeks) by Bruce Tate, from our good friends at the [Pragmatic Programmers](http://pragprog.com/). Now, I will admit that I’ve not actually read all of it…yet. The reason is that while I found the first several languages (Ruby, Io, and Prolog) interesting, and challenging, it was [Scala](http://www.scala-lang.org) that had a certain something that kept me wanting to know more. Mr. Tate actually didn’t care much for the syntax of Scala, and was rather pleased to move on to Erlang. Meanwhile I was off and running downloading Eclipse and the Scala IDE, looking at testing frameworks, online documentations, and what’s this? Android development with Scala!?!? I was hooked. What is Scala all about? 2003 - A drunken Martin Odersky sees a Reese’s Peanut Butter Cup ad featuring somebody’s peanut butter getting on somebody else’s chocolate and has an idea. He creates Scala, a language that unifies constructs from both object oriented and functional languages. This pisses off both groups and each promptly declares jihad. James Iry - A Brief, Incomplete, and Mostly Wrong History of Programming Languages ...

31 July 2011 · 9 min