Using shorter UUIDs

UUIDs make great identifiers – ones that are, for most practical purposes, unique, easy to generate, and hard to guess. The only problem is that they are long – 256 bits, but with a textual representation that’s 36 characters. So what if they were shorter?

Continue reading “Using shorter UUIDs”

Object equality is context sensitive

Equality is context sensitive. It’s very rarely as cut-and-dried as people think it is.

As a simple example, consider two $5 notes. I think everyone can agree that these notes have the same value – they are both worth $5. But are they equal?

Continue reading “Object equality is context sensitive”

Immutable objects the lazy way

Building properly immutable objects in Java can be annoying, especially if they’ve got a bunch of properties – too many to put into a readable constructor.1

You can implement the Builder pattern, but a lot of the time that just feels like overkill. But you don’t want to put in a bunch of setter methods, because that’s just asking for trouble. So what do you do?

Continue reading “Immutable objects the lazy way”

Java, Equality, Mutability

TL;DR version: Don’t implement equals() on mutable objects.

This is a post I’ve been tossing around for a couple of years, ever since a lunchtime debate with a colleague. It’s a simple statement: You shouldn’t implement the equals() method if your object isn’t immutable.1

Continue reading “Java, Equality, Mutability”

Example Hadoop Job that reads a cache file loaded from S3

I had all sorts of problems getting my head around how cache files work with Hadoop. Finally, I stumbled across the answer – when you add a cache file (see HadoopMain#48), it’s available to read as a local file inside the mapper (MyMapper#36).

When running in Elastic MapReduce, the file URI can be an S3 file, using either s3://bucket/path or s3n://bucket/path – this may or may not work in other Hadoop implementations, but the general approach would work fine.

See the gist at https://gist.github.com/twasink/8813628

Building Dependent Maven Projects in Bamboo

For the last year or so, I’ve been using Atlassian’s Bamboo (in the OnDemand variant) for our team’s build server. And, mostly, it’s an awesome tool. Some parts, however, are a little rough around the edges. Building dependent projects is one of them.

Continue reading “Building Dependent Maven Projects in Bamboo”

Jersey – a review

We’ve been getting more interested in using RESTful web services and AJAX based applications recently. One of the tools we’ve been using with that is Jersey – the JAX-RS (JSR-331) reference implementation. I’ve been using it in anger for about a month now, and thought I’d write up some thoughts I had about it.
Continue reading “Jersey – a review”

The rumours of Ruby’s death are greatly exaggerated…

Sheesh… it seems like every man and his dog is jumping on the latestTIOBE index figures showing a very> small dip in the popularity of Ruby. Talk about lies, damned lies, and statistics…

Continue reading “The rumours of Ruby’s death are greatly exaggerated…”

XML, java.io, and the Composite Pattern

Tony Obermeit posted a question to the AJUG-QLD mailing list asking for help with a problem reading XML snippets. So, I thought I’d help him out, and this is the answer I gave.

*Update*: As pointed out by Pepijn Schmitz, Sun already provided the same solution: java.io.SequenceInputStream

*Another update*: I raised an RFE with Sun for the vararg support Vote early, vote often!

Continue reading “XML, java.io, and the Composite Pattern”

Line counts are a silly way to compare languages

Des Traynor did a little post about how languages are not all the same, and Jeff Atwood jumped in with a C# version. Java came out looking really bad at 15 lines for a simple program, but frankly, the reason isn’t because of Java; it’s because of the coding styles used.

Continue reading “Line counts are a silly way to compare languages”