Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


123 Street Avenue, City Town, 99999

(123) 555-6789


You can set your address, phone number, email and site description in the settings tab.
Link to read me page with more information.


Deceptively random thoughts

Adding local docsets to Xcode

Mark Thomas

I've been playing around with core-plot, a graphing library for MacOS/iOS, which ships with a local dotset.  A normal double click on the docset from Finder wasn't enough to read it, after a bit of Googling the solution seems straightforward:

  1. Shutdown Xcode.
  2. Copy the .docset in to ~/Library/Developer/Shared/Documentation/DocSets
  3. Restart Xcode.

If you want to check that Xcode has picked up the new docset then look in Xcode Preferences under Downloads.

Sonar: Understanding your codebase

Mark Thomas

Large code bases can be difficult to understand, particularly for a new joiner to a team. Reading code is a great way to get the detail, but getting a high-level view can sometimes be hard. There are a range of open source tools that can provide Information about code coverage, design attributes and complexity, but it is often hard to extract the useful information from the volume of data produced by these tools. Critically it can sometimes be hard to visualise how this key information changes over time, and so get an idea of how your codebase is evolving. I've been experimenting recently with Sonar. Sonar provides a neat dashboard for viewing data about your project generated by tools such as PMD and Findbugs. It is fed by a build task that runs these tools in your build and uploads data in to the Sonar database. The really cool part of this, is that over time you can use Sonar to see trends in your codebase.

Sonar - Tapestry 5 Demo
Sonar - Tapestry 5 Demo

Take a look at this demo site for an example showing Tapestry 5 metrics: Between January and March you can see an increase in complexity but a decrease in code coverage. Through Sonar's different views, you can look at projects from a module, package or class level and understand hotspots that are contributing to the trend. It really is quite a valuable tool.

How do I set it up

If you use Maven then it is easy, just set up a server and then run:

mvn sonar:sonar

Non Maven users aren't left out, check out Sonar Light mode.

Functional Programming Fundamentals

Mark Thomas

I've been interested in functional programming for a while, and after spending the last 12 months or so working with Scala I can really see a difference in the way I think about solving problems. So, when an email dropped in to my inbox a few weeks ago about an 'Introduction to F#' presentation by Phillip Telford at work, I jumped at the chance to attend. Phillip is a Architectus Oryzus at Trayport working on trading solutions for financial markets, before that he worked at Microsoft Research. He talked us through the basics of F# and showed off the language in a basic Twitter application and then a simulator of the Mastermind board game. Both of the applications were extremely concise and elegant, I was certainly impressed and enjoyed making the comparison with Scala.

There has been a steady flow of F# adoption in the financial services sector, I know of a couple of banks who are using F# in production applications. That combined with Phillip's presentation has been enough to get me interested in learning more. Being a Microsoft technology, I started my search for more information at MSDN and found an absolute gem in Microsofts Deep Dive lecture series.

Dr. Erik Meijer has an online lecture series covering Functional Programming Fundamentals. I'm up to Chapter 5 now and am really enjoying it. It does cover a few things I know but the focus on pure functional development is giving me a really valuable perspective. That, and I'm getting a good opportunity to learn Haskell which I'm really starting to like.

For any budding F# developer, or someone who wants to know more about functional programming I highly recommend Fundamentals of Functional Programming.

Accessing OS X shared files from Vista

Mark Thomas

I ran in to a problem trying to access folders shared on my Mac laptop with SMB from a Vista PC. Each time I tried to access a folder I got an authentication error. After a bit of digging on the web, it seems that Vista will only use the NTLMv2 authentication method when trying to connect to SMB file shares, the default configuration of Samba on Leopard does not support NTLMv2. There is a fairly easy workaround, on the Vista machine:

  1. Open Administrative Tools in Control Panel
  2. Select 'Local Security Policy'
  3. Under 'Local Policies' choose 'Security Options'
  4. Find 'Network Security: LAN Manager Authentication Level'
  5. Change the setting from 'Send NTLMv2 response only' to 'Send LM & NTLM - use NTLMv2 if negotiated.
  6. Click OK

I'm not that familiar with Vista so I don't know if the Vista version makes a different, I am running Vista Ultimate with SP1.

Scala: Case Classes

Mark Thomas

Scala's case classes are regular classes with a twist. They are designed to support pattern matching without having to write excessive amounts of boilerplate code. As a developer, I want to understand how and when case classes should be used.

How are case classes declared?

By prefixing the declaration of a class with the word 'case'. e.g.

case class Person(firstName: String, lastName: String)

How do case classes differ from regular classes?

The compiler will automatically do a few things for case classes:

Generate an accessor methods for each of the constructor parameters
For each of the constructor parameters that is not already marked with a val or var modifier, a val modifier will be inserted. In effect, this will generate accessors for all of the constructor parameters.

Generate an extractor object
The compiler will also generate an extractor object. This supports pattern matching and means that 'new' is not required to create a new instance of a case class, so the following is valid:

val mark = Person("Mark", "Thomas")

The compiler interprets a 'Person(' as a call to 'Person.apply'.

Generate equals, hashcode and toString methods
Two instances are considered equal if they belong to the same case class and each of the constructor arguments is equal according to their equals method. The hashCode is guaranteed to match if the hashCodes of the constructor members of the two instances match. And, the toString method will do something sensible :-)


How do case classes help in pattern matching?

The auto-generated extractor can be used with match to match on constructor arguments. You can match on some or all of the constructor arguments, and decompose the case class back to those arguments. For example:

person match {
	case Person(firstName, "Thomas") => println("Hi " + firstName)
	case _ => println("Hello friend - " + person)

When are case classes useful?

A quick Google search on 'case classes' reveals some controversy around two points: whether case classes can lead to over-use of the match statement breaking encapsulation, and whether case classes are needed at all given that there pattern matching abilities can be provided with just extractors alone.


The argument goes that using match is not an object-oriented approach to development, and we've exposed our constructor parameters for no good reason. In the example above, an alternative approach could have been to add a 'greet' method to Person to encapsulate the behaviour of formulating the greeting inside the Person class. This is a valid concern and was my first concern when I thought about using case classes, however as Martin Odersky points out in a blog post there are times when 'decomposition on the outside' can be more preferable to 'decomposing on the inside'. Or put another way, where a solution based on OO-decomposition can be less readable or more contrived than one that is not. From Martin's post this is my favourite illustration of where pattern matching, based on type, can lead to a good solution:

try {
} catch {
  case ex: IOException => "handle io error"
  case ex: ClassCastException => "handle class cast errors"
  case ex: _ => "generic recovery"

We can't put the recovery code in to the exception class because it is context dependent, and whilst we could probably do something clever with the visitor pattern it would be painful. Martin identifies two cases where he believes that 'decomposition from the outside' is preferable to 'decomposition from the inside':

  1. when a computation rule involves several objects
  2. when a computation cannot usefully be defined as a member of the class on which we want to differentiate

Switch statements are not inherently bad but they are easy to abuse, the key as developers is understanding the best way of decomposing your problem domain and choosing the best solution for your situation.

Are case classes needed?

On this I'm not sure. Pattern matching can be enabled using extractors alone, but in some cases where data encapsulation is not a concern then they can provide a convenient approach. I hope that as my experience with Scala increases, I will be able to better answer this question.

Other uses for case classes?

Case classes provide a good way of implementing the visitor pattern because they provide a way of doing multiple-dispatch. I'll save that for another post.

Scala: Dependency Injection Using Structural Typing

Mark Thomas

Scala has a powerful type system that enables different patterns for expressing dependencies compared with languages like Java or C#. Jamie Webb described an interesting approach using structural typing on the Scala User Mailing List (link to post). Jamie injected a config object defined using a structural type. This has the benefit of clearly defining the dependencies of a class, whilst allowing the same environment object to be shared. Here is an example from Jamie's post, which describes a coffee warmer with a dependency on a heater and a pot sensor, the code shown is a modified version from a blog post by Jonas Bonér which uses constructor-based dependency injection:

class Warmer(env: {
  val potSensor: SensorDevice
  val heater: OnOffDevice
}) {
  def trigger = {

A simple config object can then be defined instantiates the pot sensor, heater and wires up the warmer:

object Config {
  lazy val potSensor = new PotSensor
  lazy val heater = new Heater
  lazy val warmer = new Warmer(this)

This seems like a nice pattern, it's quite elegant, type-safe, easy to test and makes the dependencies of a class explicit. There are a couple of other patterns in this area, I'll make further posts around those.

Politics and the iPhone (Obama '08)

Mark Thomas

The Obama campaign have launched an application for the iPhone which I'm sure will be loved by political junkies across the world. Alongside all of the features that you'd expect, like updates on the campaign and Obama's position on various issues, it has a few features that make use of the features of the iPhone. It hooks in to the iPhone address book and lists contacts by state, highlighting the battleground states and giving users a score based on how many of those people they have called. The application was built by volunteers and is a great example of how one constituency, geeks, are getting involved in the political process. I wish people were as engaged in politics in the UK.

Take a look at Obama '08 on the iTunes store:

Beta eBooks

Mark Thomas

I've just picked up a beta copy of iPhone SDK Development from The Pragmatic Programmers. At first glance it looks very good and will help scratch an itch that I have to develop an iPhone app. It's the second 'beta' eBook that I have bought, the first being Programming in Scala from Artima, I've spent a lot of time with this book and am completely sold on the idea of publishers releasing eBooks online early and often. Many of the advantages parallel those for software: For authors/publishers:

  • an early indication of interest in the title, are people willing to buy it?
  • a large number of readers willing to provide free feedback on the existing content
  • opportunities to build a community around a title and to allow the community to influence its development
  • by the time the book makes it to print, it will be polished and fill a demonstrated need for a title

For readers:

  • early access to useful material
  • discounted purchase prices
  • quality levels similar to a published title
  • the opportunity to ask for areas that you would like to be covered to be included

For technical books I think it is the right approach, but there is still some room for improvement. The biggest frustration I have is not being able to understand what has changed between releases. I'd like some sort annotation so that I can decide which areas I should re-read, and maybe some sort of simple voting mechanism to make it easier for me to provide feedback to an author quickly.

For fiction, I'd like to see an author try to carry on the experiment that Steven King started with The Plant. For titles like The Plant, the anticipation of future updates or new chapters adds to the fun of reading the book.

Scala: Traits and Self Types

Mark Thomas

Scala has a few features that, for those who come from a Java or C# background, provide new ways of modelling components and services. I'm going to write a few posts on this, but begin by describing some of the language features that enable them. First up is traits.

What is a trait?

A trait is a collection of fields and methods. Traits can be mixed in to classes to add new features or to modify behaviour. Scala's Ordered trait is a good example of this:

trait Ordered[A] {
  def compare(that: A): Int

  def <  (that: A): Boolean = (this compare that) <  0
  def >  (that: A): Boolean = (this compare that) >  0
  def <= (that: A): Boolean = (this compare that) <= 0
  def >= (that: A): Boolean = (this compare that) >= 0
  def compareTo(that: A): Int = compare(that)

By mixing-in Ordered to a new class, then you can get four useful operators by just implementing compare. This is quite powerful, for example:

class Money extends Ordered[Money] with SomeOtherTrait {

  def compare(that: Money) = {

As classes can be composed of many traits, this creates a powerful way of building richer classes from simpler ones by layering in capabilities.

Self Types

Ordered can be mixed in to any class; it doesn't depend on any methods or fields of the class that it is mixed in to. Sometimes it's useful for a trait to be able to use the fields or methods of a class it is mixed in to, this can be done by specifying a self type for the trait. A self type can be specified for a class or a trait as follows:

trait SpellChecker { self =>

self within the context of this trait will refer to this. Aliasing this is useful for nested classes or traits where it would otherwise be difficult to access a particular this. The syntax can be extended to specify a lower-bounds on this, when this is done the trait or class can use the features of this lower-bound class, so it can extend or modify its behaviour.

trait SpellChecker { self: RandomAccessSeq[char] =>

The compiler will check that any class in a hierarchy including SpellChecker is or extends RandomAccessSeq[char], so SpellChecker can now use the fields or methods of RandomAccessSeq[char]

Scala: Type safe duck typing

Mark Thomas

If it walks like a duck and quacks like a duck, I would call it a duck. Duck typing uses the set of methods and properties of an object, rather than its position in a type hierarchy to decide what you can do with it.

Scala's structural typing feature provides something close to duck typing in a type safe way. A structural type is close to a .NET anonymous type; a type with a set of methods and properties but with no name. An example in Scala based on one of Wikipedia's examples of duck typing:

class Duck {
  def quack = println("Quaaaaaack !")
  def feathers = println("The duck has white and gray feathers.")

class Person {
  def quack = println("The person imitates a duck.")
  def feathers = println("The person takes a feather from the ground and shows it.")

def inTheForest(duck: { def quack; def feathers }) = {

The inTheForest function declares that it will accept any object that has a quack and feathers method, both of which take no parameters and return Unit (like void in Java/C#). When executed, the code works as expected:

scala> inTheForest(new Person)
The person imitates a duck.
The person takes a feather from the ground and shows it.

scala> inTheForest(new Duck)
Quaaaaaack !
The duck has white and gray feathers.

To demonstrate the type safety, lets try using a string:

scala> inTheForest("Duck")
:6: error: type mismatch;
 found   : java.lang.String("Duck")
 required: AnyRef{def quack: Unit; def feathers: Unit}

When is this useful? Mostly in situations where you are consuming classes that follow common conventions but have no shared interface, in this case you can define the parts you are interested in by using the structural type as an implicit interface.

Finally, if you find that you are using a structural type a lot, it can define it in one place:

object UsefulTypes {
  type Duck = { def quack; def feathers }

inTheForest can then be declared as:

import UsefulTypes.Duck

def inTheForest(duck: Duck) = {

Project Cancellation

Mark Thomas

Project cancelled
Project cancelled

A well run software project should have a set of objectives that it is trying to meet. Sometimes projects will fail or be cancelled when it becomes clear that those objectives cannot be met within constraints, such as time-scale or budget, that form part of the project's business case. When a project is cancelled, it can have a profound impact on the team. It is important to manage the process of cancellation so that team members can smoothly transition in to their next project.  How this is handled can impact team members' productivity now and in the future, as well as their perception of the company and its managers.

Team members should understand the reasons for project cancellation and believe them, if possible the teams should be part of the discussions around cancellation even if they can't influence them.  Once team members leave the project they should be rolled on to new projects as soon as possible and given productive work to do.

It is important to realise that project cancellation is often the right action.  Projects are planned based on imperfect information; as projects progress and teams learn more then the decisions on project viability can change too.  Often it is difficult to act on this changing information, particularly in public sector projects, as it could directly impact the reputation of the project sponsors, and undermine the strong emotional engagement that team members have made in delivery.  To make the best decisions, projects should be monitored continually, and early and regular feedback obtained from all project stakeholders so that informed decisions can be made and openly communicated.

At the end of a project, a project retrospective should be run to give the team an opportunity to take stock and take away lessons for the future.  Retrospectives should be balanced, looking at the good and the bad and providing a basis for team members' future work and a celebration (cue the beer) of the teams achievements.

Ever wondered where your time goes?

Mark Thomas

Slife is a great free app for the Mac that sits in the background and logs how much time you spend in each app that you have running. By telling it when you start a new activity, it will give you an idea of how you spent your time during that activity.  So, for example if you are trying to 'Implement a basic Rails app', you can find out how much time you spent reading e-mail, browsing the web or editing your source.  I found it quite enlightening and it made me think more about ways that I can stay more focused.

If you want to understand where you time goes and you have a mac, Slife is the app for you.

Thanks to Floyd for the tip.

Moving from Java to C#

Mark Thomas

After about 10 years working primarily in Java, I'm a few weeks in to my first commercial C# project. The transition was much smoother than I'd expected and after some head-scratching around the syntax additions in C# 3, I feel productive. I'm surprised how little time I have needed to spend learning the .NET framework libraries and exploring the .NET open source community.  As a business app, most of the code I am writing models the domain and interacts with other parts of the domain; it is all written by the team.  With the exception of things like the collections classes, most of the framework/library interaction is on the fringes of the system.  That said I've done my fair share of Googling things like 'How do I parse XML in .NET', but the community is large and so it's easy to find solutions to problems. A harder part is learning C# idioms, the Manning book C# in Depth was great for this (see later) as were chats with my teammates and pair.

Along the way I've picked up a few useful resources:


Other thoughts

  • Get Resharper
  • If you are familiar with Java IDEs like Eclipse or IntelliJ and regularly re-factor then you will need Resharper. The out of the box support for refactoring is minimal even in VS2008.

  • Remember there is an eco-system outside of Microsoft
  • Many companies having selected .NET will automatically favour Microsoft solutions for everything. Even though the open-source community doesn't appear as vibrant as for Java, it does exist. Check out too.

Polyglot programming with IntelliJ 8

Mark Thomas

Artima interviewed JetBrains's Dmitry Jemerov at JavaOne 2008 back in June, the interview notes are here: Dmitry makes some interesting comments around Polyglot Programming and how Jetbrains plan to add new language support to IntelliJ. I'm glad to see a move towards more modularisation and particularly a way of specifying which features to enable (e.g. Java, SVN etc) and even for disabling Java when using another language. This change should go a long way to addressing the bloat, and sluggishness, of earlier IntelliJ releases.

The most exciting feature for me is Scala support. I'm a big fan of Scala, but I see two barriers to adoption: the available documentation is limited, particularly good examples; and it's quite a complex language. Dmitry touched on this last point but I don't really agree that it's as complex as C++. Artima have a Scala book in the works which is a fantastic way to pick up the language.

The IntelliJ EAP releases can be downloaded from

Lotus Notes 8.5 won't launch on Mac OS X 10.5.3/10.5.4

Mark Thomas

IBM have released a public beta of Lotus Notes 8.5 for the Mac. It seems a lot better than version 7, but after applying the OS X 10.5.3 update I found that I could not start Notes. The only feedback of a problem was in the system log: [0x0-0x34034][546] maclauncher: unrecognized option `-psn_0_213044'

The workaround I'm using is to run the 'Notes' application from inside the application bundle. From the terminal:


There is a discussion on the IBM forums covering this so I hope it will be fixed in the next public beta:

Radiohead in Victoria Park

Mark Thomas

I saw Radiohead play in Victoria Park last night, great music, great beer, great company, great weather, long queue for chips ;-)  About half way through a Tibetan flag appeared on stage to chants of 'Free Tibet', I'm sure I heard a few shouts of 'Free Beer', honestly it wasn't me!

LLVM-GCC and Clang

Mark Thomas

At the WWDC, Apple talked about LLVM-GCC and Clang.  LLVM-GCC takes front end components of GCC such as the language parsers and builds LLVM platform independent intermediate language (similar to JVM bytecode).  LLVM can then provide link-time optimisations, JIT compilation, dynamic code generation for this IL.  Backends exist for emitting code for a number of processor architectures as well as MSIL. Clang is an Apple led project to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler, essentially removing the need for LLVM-GCC.  It's an interesting move by Apple that leaves them free to better integrate a compiler into Xcode without some of the restrictions imposed by the GPL.  For a technical comparison with other compilers including GCC see here:

At first glance, LLVM is an interesting technology that seems to provide a more modular solution compared with compiling to JVM bytecodes or MISIL, allowing a language implementer to take advantage of the LLVM IL optimisations and runtime environment if they want to.  There is an LLVM sub-project called vmkit, which is working towards binary translation from Java bytecode and MSIL to LLVM IL, it'll be interesting to see how it performs compared with Sun's Hotspot VM which they have tuned over many years, some pre-Java.

Apple are targeting speed improvements and a reduced install footprint for Snow Leopard (OS X 10.6).  It seems that LLVM-GCC and maybe Clang are driving some of these improvements.  Apple are claiming around a 33% performance improvement when compiling code with LLVM-GCC compared with just GCC, and by shipping LLVM-IL applications rather than fat apps containing x86 and PPC versions they could reduce the install footprint.

This is very cool: Apple are using LLVM as part of the OpenGL stack in Leopard