Rewriting Java in Scala & Making Code Lovely 6 - Pattern Matching

Pattern Matching - The Problem I'm going to start off with a code snippet: if (x instanceof SomeObject) { ((SomeObject)x).someMethod(); } else if (x instanceof SomeOtherObject) { ((SomeOtherObject)x).someOtherMethod(); } Eugh. This is ugly. Not only that, it's something we all see quite often when writing Java. No matter how well ... Read more

Rewriting Java in Scala & Making Code Lovely 5 – Structural Typing

What is structural typing? Structural typing is a way of saying that we don't care about the type of a variable but we do care about the structure of the type of a variable. Here's a simple example to explain this further: def printArea(shape : { def area : Double}) ... Read more

Rewriting Java in Scala & Making Code Lovely 4 – Example: Integration

It's time for a full example that shows off what we know so far. For the example, we're going to implement something that does basic integration. This program will approximate the value of an integral using the rectangle method - a good explanation of this can be found here. Background ... Read more

Rewriting Java in Scala & Making Code Lovely 3 – Variable Declarations

I thought I'd take a step back and look at how variables are declared in Scala and how it compares with Java. Local Variables In Java you declare a local variable like this: Map<String, Integer> userIds = new HashMap<String, Integer>(); In Scala, it is a lot shorter: var userIds = ... Read more

Why val and var rock

When discussing val and var in Scala they are often seen as the alternative to Java's more long winded way of declaring variables, e.g. Employee bob = new Employee("Bob"); vs var bob = new Employee("Bob") The latter is clearly more succinct and has less repetition. This is normally where the ... Read more

Rewriting Java in Scala & Making Code Lovely 1 - Case Classes

This is the first in a series of posts for people who know Java and are learning Scala. Apart from teaching Scala I hope these posts show how Scala makes your code lovely... What does more lovely mean? Lovely covers several things: More concise More readable Easier to debug Easier ... Read more

Introducing Gleam

Over the past few months I have been working on a new programming language for the JVM. It's called Gleam and its purpose is to make view layer programming for web applications easier. You can read more on the approach taken and the problems it is trying to solve here ... Read more

Rewriting Java in Scala & Making Code Lovely 2 – Functions as values

Ever wanted to filter a collection in Java and thought "this sucks"? Typically, you end up with code like: List evens = new LinkedList(); for (Integer i : list) { if (i % 2 == 0) evens.add(i); } Or, if you're going for re-use: Predicate evenNumbers = new Predicate() { ... Read more

Fun - The undersold benefit of Scala

I've seen a lot of arguments lately comparing Scala to [insert any language here]. The arguments are normally based on some mix of conciseness, static typing, functional programming and the actor model. However, I've yet to see anyone arguing for the main reason I'm drawn to Scala: it's fun to ... Read more

Language Wish-List: Add Information to Exceptions

Following a discussion over on David MacIver's blog. I have a piece of functionality I'd like to see in more languages. The ability to easily add information to exceptions try { // ... } catch (Exception e) { e.addInformation("serverName", serverName); throw e; } Or, even better, a way to annotate ... Read more

Type Burdened

I've been trying to collect my thoughts on why I prefer Scala's type system to any other that I've come across. To summarise: it has type safety and just the right amount of type burdening. What is type burdening? Type burdening is a consequence of type safety. The more you ... Read more

RK4 in Scala

I've been looking at Scala recently and I'm impressed. It's got a nice mix of imperative and functional styles that means that it can be really useful and easy to code in. As an example I thought I'd knock up an implementation of RK4 in it. The work-horse of RK4 ... Read more

Sick Things in Scala: Implicit Conversions of Functions

I've been having a play with seeing just how far Scala can be bent before it is broken. My latest finding is that you can implicitly convert functions to other types. For example: object Sickness { class WrappedFunction implicit def functionWrapper(f : => Unit) : WrappedFunction = { System.out.println("Going to ... Read more

Colin Howe

I'm Colin. I like coding, ultimate frisbee and startups. I am VP of engineering at Conversocial