Categories
Uncategorized

Junit 4

I’ve got a little project at work that’s completely new (hurrah!), and using Java 5. So, I thought I’d give the latest Junit a try. Junit 4 is quite a departure from the older versions. It relies on features only present in Java 5, like annotations. But this does free up the tests from having to inherit from TestCase.

This is the simplest test case.

  import org.junit.Assert;
  import org.junit.Before;
  import org.junit.Test;

  public class MyTest {
    @Before
    public void setUp() throws Exception {
      // ...
    }

    @Test
    public void alwaysTrue() {
      Assert.assertTrue(true);
    }
  }

You can make this slightly nicer by using static imports for the assertions. I didn’t because I wanted eclipse to complete them and I couldn’t auto-discover them as easily. I’ll probably switch shortly.

The annotations are also used for stating which exceptions you wish to catch.

All in all, I’m quite impressed. It’s about as simple as it gets in Java.

Categories
Uncategorized

Syd Barrett Departs

Sad, sad, news today: Pink Floyd’s Barrett dies aged 60. He had a tragic life, yet produced some of the most beautiful music I have ever heard.

Shine on…

Categories
Uncategorized

Hibernate In Action

In the same way that we’ve been checking out web frameworks for Java, we’ve also been looking at persistence layers. Despite strong recommendations for iBatis, we’ve ended up going for hibernate, largely because “it’s what everybody else uses”… So I’m learning my way around Hibernate, aided by the Hibernate In Action book. Now the book seems quite reasonable so far at explaining why Hibernate is so damned complicated (this is my 3rd ORM I’ve used, yet it still seems weird and bloaty). My pain starts when I get to the second chapter, where the code starts.

The main problem is that the very second example comes unstuck. The first line is:

  Session session = getSessionFactory().openSession();

Where is this magical getSessionFactory() coming from? Looking it up in the index sends me to page 314, smack into the middle of the “the session fa├žade pattern”, where an implementation that probably won’t work for me sits. Thankfully, I can spot the obvious bit:

  new Configuration().configure().buildSessionFactory();

But why on earth dont they put this in chapter 2 where it belongs? I’ve got code sitting in front of me that I can’t run, and that’s a crime.

Oh, on top of that, turning the page reveals the phrase “the code fragment prints…”. Well, it would if I had a hibernate config file to go with the mapping file that they presented. What a waste of my time figuring all this out. I’m just glad I didn’t pay for this book (work did).

Alright, turning a few pages further on we get to “Creating a SessionFactory”. That’s better. But there’s still no excuse for code samples you can’t run.

Categories
Uncategorized

Stripes

After much gnashing of teeth and wailing, we’ve finally found a web framework for Java that looks usable. Stripes looks simple enough to be usable without requiring insane amounts of configuration. It also uses Java 5 features like annotations and generics to great effect. Plus, minimal configuration files. I strongly recommend checking out the Quick Start.

It’s not rails (by a long shot), but seeing as how we are forced to use Java at work, it seems to be one of the least unpleasant options so far.

Categories
Uncategorized

The Deployment Elephant

Tim O’Reilly covers much of what’s been crossing my mind recently in Operations: The New Secret Sauce. The really successful people are those who (like Google) have solved, and are continuing to solve the really hard problem of deployment. There is a huge gulf between programmers and sysadmins that needs to be crossed so you can get software that works really well. It’s all very well writing code that works “great on my PC”, but when you have to stick it on a Unix server blows up (reminds me of the “Best Viewed On My Monitor” graphics that festooned the web a few years back). We can and must do better.

Part of the problem is that nobody is seriously talking about deployment. During our company’s recent move towards Java, I’ve found it seriously hard to work out what best practises are and have already gone through several painful experiences working things out. Yes, this is part of the normal learning curve. But it would have been really, really nice to look them up in a “Deployment Patterns” book.

Update: on a tangentially related note, Steve Loughran notes:

There is a very simple test to see if the deployment process is working. If you have to go into the air-conditioned server room on a weekend or on your vacation, deployment is broken. If you are scared of the mobile phone ringing, because it may be the operations team, deployment is broken. If you are a week away from going live and you haven’t started bringing up the server, then the process is broken, you just don’t know it yet

Categories
Uncategorized

The Treason Show

I went to see The Treason Show last Friday night. It’s about the fourth time I’ve been and I’m still being entertained. Song and dance satire can’t be beat.

However, I do have a couple of complaints:

  • Too much football. Really. I hate football, despise the world crap and really want to go out and get away from it. Having said that, the finale of “We’re not the champions” was beautifully done.
  • Tables. This is more aimed at Komedia rather than the show. But all the tables were a) really tightly packed in and b) reserved anyway. We got there fairly soon after it opened and there were no free tables (they were empty, just unavailable). Instead, we got to sit on the very uncomfortable stools for the whole show. They really need to rethink this.

Overall though, still very enjoyable, despite the extremely loud and pissed woman two tables down.

Categories
Uncategorized

LibraryThing

A few days ago, somebody at work showed me LibraryThing. It’s the application I’d always wanted to build myself for managing my books. And now somebody’s done it for me. I’ve now chucked all my computer books in and they’re available at: librarything.com/catalog/happygiraffe. By which you can safely conclude that I have spent too much money on books over the years.

The main downside to LibraryThing that I experienced was incredible slowness at times. However today, the message is up that it’s moving on to new servers. So hopefully a speedier experience is ahead!