Uncategorized

You are currently browsing the archive for the Uncategorized category.

August is the month for the big summer blockbusters, three in total.

The A-Team is a failed attempt to revive a well-loved franchise. First, the good: both Bradley Cooper and Sharlto Copley were great as Face and Murdoch, using all the right ticks for those characters. Some of the action sequences (i.e. the numerous explosions) were decent enough. That’s about it. The rest was a mish-mash of nonsensical plot, with too many pointless threads and characters. Given the film was trying to establish four strong leads, adding a half dozen other people to the mix really left little time for much else. Liam Neeson’s Hannibal was an interesting idea, portraying him as a meticulous and obsessive planner, but we don’t get enough time with him to really see it pay off. Quinton Jackson’s take on BA was pretty poor. Rather than being the mean, near invulnerable hulk of the series, we get a generic brawler who, to add yet another sup-plot, finds religion. There were some good ideas on show, but they were drowning in franchise building, dumb plotting, and the apparent need to move to the next action set-piece. Poor. (See my A-Team Twitter review).

The Expendables, on the other hand, made to qualms about what it was. Sure, the plot was perfunctory and the characters paper-thin, but that was the point. It was all about getting the biggest action movie stars of the last three decades together to revel in their artform. It’s a big dumb action film, with all the explosions, guns, and hand-to-hand fighting you could hope for. If you want a story, don’t bother. If you want to see Stallone fight Lundgren, then this is the film for you. (See my The Expendables Twitter review).

Finally, Salt is a fairly straightforward action-thriller. It borrows heavily from the improvisational spy style of the early part of the Bourne trilogy, but without either the story or meaty contact to really see it through. While a handful of the set-pieces are genuinely well-done, they get lost in the predictable “twists” of the thriller plot. It’s the usual 24-style movie-plot threat and by the time it actually happens you really won’t care. A shame. (See my Salt Twitter review).

The winner is The Expendables, for it’s no-nonsense action sensibility. It would have lost in many other months, but up against two other action films, it’s no contest.

As is the norm, July was a reasonably full month with 4 films viewed.

Predators, while not a masterpiece by any measure, is exactly what it needed to be: an action movie with an 80′s feel, free from large CG scenes and full of physical effects, enough of a plot to put the cannon fodder where it needed to be, and some absolutely great scenes. The pre-credits opening shot is particularly grabbing, pushing the audience immediately into the action and getting things started with some panic. Adrien Brody doesn’t pull-off being an action hero in the same way that Schwarzenegger did, and the slow reveal of the predators themselves was something of a waste, given we know what they look like from the rest of the franchise, but those are small points in an otherwise solid film. (See my Predators Twitter review).

There’s a lot I would like to say about Christopher Nolan’s latest masterpiece, Inception, but can’t do so without leaving a large trail of spoilers. There will be many fiercely argued debates about the minutiae of it’s world and it’s take on subjective reality. That’s how you know it’s going to be a classic. Nolan has created an incredible piece of cinematic storytelling, full of visuals and world-building that wouldn’t work in any other medium. The central conceit of controllable dream worlds is revealed just as quickly as it needs to be, just like everything else in this film from Leonardo DiCaprio’s broken team lead to the depth of the maze that is being built in the incredible plot. That, as I see it, is its only major flaw: everything moves so quickly that only the central concept and DiCaprio get a chance to breath. The supporting cast (and a great cast it is) provide excellent sketches of characters and there are many questions to be asked about them, but we never get the time to see any of it. When the only real criticism you have of a movie is that you want to see a lot more, you have a classic. A fantastic, must-see film. (See my Inception Twitter review).

Pixar’s latest effort is a new look at an old franchise. Toy Story 3 revisits Woody, Buzz and friends ten years later as Andy, their owner, prepares to go to college. The central theme of transition and moving on sets a tone that is both sweet in places, and fairly sad in others. That’s not to say it’s not got the little adventure set-pieces of the previous films, it has quite a few that will make you laugh, but it is less overtly funny than its two predecessors. Revisiting a franchise this long gone is dangerous, but Pixar have done well to put a neat little ending on this story. A great film. One other note: the 3D effects are understated to the point that they actually don’t add anything to the film. If you saw this in 2d, you’d still have the same great movie. (See my Toy Story 3 Twitter review).

I had high hopes for The Karate Kid, a thematically different take on the story structure of the 80′s classic. In the opening chunk, some of my hopes were lived up to: we see the frustration and loneliness of a young boy pushed into a foreign situation. Had the film built on this theme, it could’ve been a great film but it was there just as the set-up for a much more formulaic movie. Jaden Smith managed to get the emotional points across pretty well for an actor of his age, but failed when it came to anything approaching comedy: he has the mannerisms of his father, without the brash charm to pull it off. For a film lacking in depth and out-and-out fun, it certainly ran a lot longer than it should have. The plot on offer could’ve been covered in 90-odd minutes, but we’re given nearly an hour more than that. A shame. (See my The Karate Kid Twitter review).

While I really enjoyed Toy Story 3, this month’s winner is Inception for its clever storytelling and THAT hotel corridor scene.

In the Modern Java series, I’ve looked at how Lombok removes boilerplate from bean classes, JSR-303 validation makes checking domain correctness neat and how JPA provides a convenient standardisation over the ORM space. Each of these technologies does something interesting and in an interesting way.

The point of this series, however, was not to try to provide any deep level of insight into any of those technologies; writing anything even approaching a useful tutorial about JPA alone would take up many more posts than I had ever intended on giving the subject. There is simply too much there, and too much intricacy involved to sum that up.

No, the point of this series was multi-faceted, and I’d like to take another few moments to try and explain what I was trying to achieve.

Firstly, the primary concern for designing good systems is understanding the domain of interest. If you don’t understand the domain well, you won’t be able to produce a nice user experience at the front-end. You won’t be able to write meaningful abstractions at the back-end. You won’t be able to write something that you can pick up a year or two down the line and immediately understand. Knowing and understanding the domain is a prerequisite for good design.

What does that have to do with the libraries I discussed? Each of them help you design in terms of the domain and only the domain. Lombok helps you write domain objects without all the cruft in the way. Standardised validation makes sure the correct rules are cleanly annotated and enforced on those domain objects. JPA ensures that when instances of those domain objects are persisted, they are persisted following a series of rules that make sense for the domain. Each of the libraries pushes you down a path of thinking about your domain and hiding other more mundane concerns.

Secondly, I wanted to show that clean code is infinitely preferable to cluttered code. In the examples I gave, I showed a simple bean class being built up with just a handful of annotations, each one describing it’s own purpose and providing a clean understanding of the domain. As a thought experiment, consider what that code would be like without the annotations. Imagine the number of classes and methods that even a well-designed alternative would have to orchestrate. While I’m sure it could be quite neat, I can’t imagine a solution quite as neat as the one offered by the technologies I mentioned.

That leads into my final point: modern Java features, such as annotations, and the libraries that make use of them allow for much richer, cleaner and downright better code than has been possible previously. I won’t try to argue that Java is perfect as a language as I like many of the alternatives, such as Scala, Groovy, Haskell, Ruby, Python and many others. What I am trying to say, though, is the situation with the Java language is a lot better than it was five years ago, when typical Java code was verbose, unsightly and headed away from the domain. It often obscured the domain, rather than illuminating it.

My hope is that future iterations of the language and future libraries continue to keep Java in a competitive place in the language market, by making even more problems domain-focused and removing the remaining boilerplate. With the Project Coin and Project Lambda improvements due in Java 7 later in the year, I really think this will be the case.

Three new films this month, all quite different.

Rec 2 picks up immediately after the ending of Rec, with a SWAT team about to enter the quarantined Spanish apartment building. Rather than shy away from the weak ending of the original, it embraces it and builds a fairly silly plot around it. There’s all-sorts of terrible tell-don’t-show storytelling on display here, and that undermines a good amount of the work done elsewhere. Despite a forgettable plot, the audio-visual design is fantastic: in-camera glitches, sound breaking up and distorting in just the right way to make you squirm, and THAT scene with the boy. Genuinely creepy horror in places, let down by the plot changes. (See my Rec 2 Twitter review).

The Killer Inside Me is, if nothing else, beautifully shot with art-direction in the opening credits that most films can’t muster in 90 minutes. The look throughout is striking, whether we’re observing the lead sitting in a chair or brutalising another character needlessly, and he brutalises other characters frequently. There are several fairly uncomfortable, difficult scenes here; scenes of reasonably extreme violence against women (in the context of modern cinema, at least). While they’re extremely powerful and shocking moments, they sit amongst a plot that for the most part lurches along and doesn’t really get anywhere. The film is purposefully rife with ambiguity as we, the audience, try to fill in the gaps around why the lead is such a cruel and twisted man. Sadly, it’s just not interesting or well-done enough to really bother. The idea of irredeemable characters, monsters for their own sake, has surely been done better than this many times before. (See my The Killer Inside Me Twitter review).

Finally, Shrek Forever After marks the supposed end of the series, with Dreamworks claiming they won’t make any more. I wish they’d stopped at least one film back (perhaps two). The latest film in the series is definitely not a classic, lacking the originality, creativity or joy of the original Shrek. The plot is fairly forgettable and largely unimportant, with the majority of the laughs (and there are some good laughs in there) coming from little visual cues. The source material here has been stretched a little too thin: had this been an episode in a 25 minute cartoon series, you wouldn’t have noticed the difference. Okay, but not great. (See my Shrek Forever After Twitter review).

While I didn’t think any of the films this month were particularly great, the winner is Rec 2. Despite a fairly nonsensical plot, it delivered where it mattered: providing a horror-filled, cinematic experience.

It may be a few weeks late, but the Film Fight for May is an extremely light one with only one film.

Four Lions is another interesting piece of comedy from Chris Morris. The premise is a comedy that follows a few would-be suicide bombers from their hometowns to training camps and back. Rather than being mean-spirited or relying on controversy, what we get is a great British farce as we see how absolutely incompetent most of the crew are. There are a few stark moments, but it’s almost entirely silly, poking fun at the idea of the bombers and their ridiculous scheme. (See my Four Lions Twitter review).

And the winner is… Four Lions. Obviously.

A reasonably busy April at the cinemas has meant another bigger-than-usual Film Fight, with five films.

Kick-Ass is a ridiculous film. It’s an absurd premise (a kid decides to become a super-hero and finds out he isn’t the first one to try it), that holds together remarkably well when paired up with intentionally over-the-top violence in a pseudo-comic book world. It’s bloody, and goes quite far at times (mostly when it uses Hit Girl), but manages to pull it off by making it clear that this is entertainment and clearly straight out of a graphic novel. While the story isn’t anything to right home about, and it has some cringeworthy moments, it remains entertaining to the end. (See my Kick Ass Twitter review).

Green Zone sees Matt Damon team back up with Paul Greengrass, in a plot pulled straight from a Tom Clancy novel. Yes, it’s the usual military-complex, conspiracy nonsense, but it is reasonably fun. It works best when letting Damon get into the action set-pieces and starts to wane whenever it goes near the reasons for the conspiracy. For the most part, a reasonable balance is found to keep things moving forward. Where it really falls down is in the comparisons that have been drawn to the Bourne trilogy. Even on the action side, this is a much more relaxed affair than the impossibly well-developed skills of Damon’s previous super-spy character. Worth seeing. (See my Green Zone Twitter review).

Comedy, good comedy, can be painfully uncomfortable. Either bringing up subjects that most people consider taboo to shed some light on them or by poking fun at preconceptions. It was surprising to see that Crying With Laughter managed to blend that discomfort so well into a fairly dark thriller so well. It tells the story of a stand-up who is at his make-or-break point, going further and darker with every show, as he bumps into someone he used to know who will give him an incredible story to tell. At moments the film is incredibly funny, and at others it’s horrific as you discover the painful memories that full the lead. A few of the minor characters aside, this is a fantastic film; that brings together two kinds of unease, and produces an excellent story from them. Highly recommended. (See my Crying with Laughter Twitter review).

Mike Judge has an incredibly strong legacy with Beavis & Butthead, King of the Hill, Idiocracy and his classic, Office Space. It’s with that in mind that it’s fairly surprising his new movie, Extract, just isn’t that funny. There are some great moments and some well-observed characters (David Koechner delivers another great small part), but a lot of it falls flat. It’s not awful, but it is entirely forgettable. (See my Extract Twitter review).

Finally, Todd Solondz returns to the characters he introduced in Happiness 12 years ago, recasting them all in a pseudo-sequel, Life During Wartime. If you liked the first film, you’ll wish he hadn’t. It has a scant few jokes that hit the familiar territory of awkwardness that Solondz thrives in, but much of it doesn’t work. As a whole, the film lacks any real cohesion, with fairly uninteresting characters not really doing much or saying anything of real value. There’s not much of a theme, just a series of moments that hang together poorly. It’s a shame because a few of them work incredibly well: the scene where Billy is reunited with his father is absolutely gripping. A quite disappointing effort. (See my Life During Wartime Twitter review).

And the winner is… Crying With Laughter, for walking the fine line between horrific and funny extremely well.

In the previous post, I showed how JSR-303 is making validation neater. I concluded that article with the Person bean looking like this:

@Data
public class Person {
    @NotNull @Size(min=1)
    private String firstName;
    @NotNull @Size(min=1)
    private String lastName;
    @Min(18)
    private int age;
}

If we know we have a valid bean, at some point we probably want to persist it so we can use it again. I won’t waste time on spelling out how much boilerplate code is written for raw JDBC calls as most developers have moved a level of abstraction up from that anyway, with great tools like Spring’s JdbcTemplate.

I also won’t go deeply into the history of ORM in Java, as a lot has already been said. The Java Persistence API (JPA) standardised fairly sensible ideas about how ORM should work, starting from real implementations (primarily Hibernate) and pulling together the main concepts. To prepare a bean for JPA persistence, we merely need to add an @Entity annotation and specify an @Id column (which I’m going to have to add to Person):

@Data @Entity
public class Person {
    @Id
    private Long id;
    @NotNull @Size(min=1)
    private String firstName;
    @NotNull @Size(min=1)
    private String lastName;
    @Min(18)
    private int age;
}

And that’s it. You can then use a properly configured EntityManager to persist() your class (the configuration details are largely implementation specific, but relatively lightweight).

There are a lot of options available to configure exactly how an entity should be persisted when passed into an EntityManager. Again, I won’t cover them all, but it’s generally considered best practice to state your table and column names explicitly (rather than relying on convention, as I have above) and you’ll often want to make use of the built-in optimistic concurrency support to stop multiple changes happening at once.

@Data @Entity @Table(name="people")
public class Person {
    @Id @Column(name="id");
    private Long id;

    @Version @Column(name="version")
    private int version;

    @NotNull @Size(min=1)
    @Column(name="first_name")
    private String firstName;

    @NotNull @Size(min=1)
    @Column(name="last_name")
    private String lastName;

    @Min(18)
    @Column(name="age")
    private int age;
}

As a bonus, if you use a JPA2 provider AND have a JSR-303 validation implementation in your classpath, the default behaviour will be for your bean to get validated before it gets persisted, so you wouldn’t have to explicitly call the validator any more.

Again, there’s a lot more to be said about JPA, and the use cases that it supports (I haven’t touched on object-graphs, embedded collections, or the Java persistence query language), but you should have a flavour for it.

In the previous post on Modern Java, I showed how Lombok is making Java beans more concise. In that post, I showed how we would end up with the following class:

@Data
public class Person {
    private String firstName;
    private String lastName;
    private int age;
}

Given an instance of that class by binding data from a web form, a database or some other data source, a fairly common requirement is to validate it against a series of rules and constraints.

For example, if we assume “age” is the number of years the person being described has been alive, we know that it must be zero or greater. Depending on our application we may also know that it’s above a minimum age (18, say) and is extremely likely to be below a maximum age (there are very few people over 100, and none over 120).

A few years ago, you would have to write a custom piece of code to validate simple rules in all of your domain classes. These would typically be specific to the class in question, running through a series of explicit checks, and produce a list of errors found. While this worked, it was often verbose and tightly-coupled to each domain class. It might look something like this:

public Collection<Error> validate(Person person) {
  Collection<Error> errors = new LinkedList<Error>();
  if(person.getAge() == null) {
    errors.add(new Error("Age cannot be null"));
  }
  if(person.getAge() < 0) {
    errors.add(new Error("Age must be greater than zero"));
  }
  if(person.getAge() > 120) {
    errors.add(new Error("Unlikely to be a real age"));
  }
  return errors;
}

Note that we’re only validating a few rules on one field, and it’s already quite verbose. If we validated every field on an object and the interdependencies between them, then we would have a lot of code.

Both the Spring Framework and Hibernate had come up with their own ways of making writing and integrating validation logic a little easier, but now validation has been standardised in JSR-303. The reference implementation is Hibernate Validator 4, and it’s a great starting point, but most uses of JSR-303 will be relatively agnostic of the implementation. Since this is a finalised specification, you can also make use of it today.

For our Person class above, let’s add the following constraints:

  • Age must be 18 or more
  • First and last name must be set i.e. they can’t be left null
  • First and last name must have at least one character in them

To implement these rules, we need only add a few new annotations, using standard constraints:

@Data
public class Person {
    @NotNull @Size(min=1)
    private String firstName;
     @NotNull @Size(min=1)
    private String lastName;
    @Min(18)
    private int age;
}

You then create a Validator instance (how you do this will depend on your chosen implementation), and pass the class in for validation:

Set<ConstraintViolation<Person>> errors = validator.validate(person);

All the validation is then handled for you, reducing the amount of code and making your bean classes very clearly state the constraints under which they operate. You know a first name is not just any old nullable string by just looking at the class, and you know ages have limitations in your particular domain of interest. The code is more expressive and concise, and that’s a very good thing.

There’s a lot more to the JSR-303 specification, and it has all the features you might want. While I fully intend to go into the other features at another time, I’d strongly recommend browsing the spec to see some of the power and flexibility available to you.

In recent months, I’ve been looking at a lot of new Java libraries to see what I’d like to use and what I think still has a way to go. I’ll be posting about them all in due course but I wanted to mention Lombok first.

First, a class:

public class Person {
    private String firstName;
    private String lastName;
    private int age;

    public String getFirstName() {
      return firstName;
    }
    public void setFirstName(String firstName) {
      this.firstName = firstName;
    }
    public String getLastName() {
      return lastName;
    }
    public void setLastName(String lastName) {
      this.lastName = lastName;
    }
    public int getAge() {
      return age;
    }
    public void setAge(int age) {
      this.age = age;
    }
}

The problem here is that everything after public int age is predictable and verbose; you know that this is a Java bean class and that the fields are likely going to have getters and setters just like those provided. If we know exactly what to expect, shouldn’t the compiler take care of that for us rather than having us specify more code? Less code is often cleaner code.

For several years now, people have been asking for the idea of properties in Java. That is, being able to define fields and automatically having standard getters and setters defined, without having to clutter the class file with boilerplate. The most common (and reasonable) response for avoiding this is that it would be difficult to implement without affecting backwards compatibility.

While those proposals are pretty much dead at the moment, Lombok saves us from having to specify our standard getters and setters by marking our classes as beans and then jumping into the compilation process to make sure getters and setters are generated. The above code becomes:

@Data
public class Person {
    private String firstName;
    private String lastName;
    private int age;
}

That’s right: the 18 or so lines of getter/setter boilerplate are replaced by the tiny little @Data annotation, and the code is much cleaner. As a bonus, @Data also generates a toString(), an equals() and a hashCode(). You can use the other Lombok annotations to tweak the behaviour, but this is what most people are going to want.

Also of note is the @Cleanup annotation, which provides automatic resource management (ARM) for using input/output streams. While this will be less essential if ARM arrives in Java 7, it’s a handy little helper for the time being.

While Lombok can’t make bad code good, it can make verbose code a lot more succinct.

The March 2010 film fight includes no fewer than 6 brand new movies. That should make up for the slightly quieter-than-usual February. Onwards…

The Crazies looked like it had decent potential: a Romero remake about an infected township, lots of explosions and action, and a little humour alongside. It blows it. The action overwhelms the story from the very beginning, moving things on to the next set-piece before really establishing any of the characters. Without anyone we actually care about, the film suffers immensely. The plot itself is as expected, but it fails to hit any of the big scares a film like this needs. It never gets better than mediocre. (See my The Crazies Twitter review).

A lot was expected of Tim Burton’s foray into Lewis Carroll’s classic novel, but Alice In Wonderland disappoints. It’s not a filming of either Alice story but a bizarre sequel/retelling. It fails by paying too much fan-service to the world of Wonderland, attempting to squeeze every character into this semi-new narrative, rather than tell a more coherent tale. The characters themselves are the high-point, with some great (if too short) appearances by the Mad Hatter and the Cheshire Cat. Does the spectacle of 3d make up for some of the story failings? No, not this time. Unlike Avatar, the effects on display are average at best. Some of the scenes work better than others, but some are clearly flat layers. There are also some frankly odd choices in the direction: tightly pulled-focus does not work in 3D. All in all, a disappointment.  (See my Alice In Wonderland Twitter review).

Crazy Heart earned Jeff Bridges an Oscar for his performance as drunken country singer, Bad Blake; and rightly so. The performances in this film are high quality, without ever getting towards scenery-chewing territory. Both Bridges and Maggie Gyllenhaal put in excellent and subtle performances, saying as much with quiet looks as with their words. The solid getting-your-life-together is marred only by a weak ending, when the central character gets his life together a little too fast to feel satisfying. A little more adversity and struggle here would’ve completed this very worthwhile film a lot better. (See my Crazy Heart Twitter review).

Martin Scorsese manages to show some great form with his latest work, Shutter Island, before ruining it with a cheap ending. The story follows a US Marshall tracking down an escaped mental patient on a small island off the US mainland. The film is spiked with a Lynch-ian vibe throughout, that something sinister is happening without being clear about what is wrong. It’s beautifully shot, if a little over-the-top in places. Leonardo Dicaprio pulls in a solid performance, but he can’t cover up the poor ending. The last thirty minutes devolve into cheap, seen-it-before cliche. A great beginning, that deserved a much better conclusion. (See my Shutter Island Twitter review).

The Girl With The Dragon Tattoo fails to live up to the not-inconsiderable hype. While some of the acting is solid, the story is full of cheap genre cliches. If you can imagine taking a high-street bestselling thriller and filming it straight-up, then you can imagine this movie: our heroes get involved in a murder investigation, working through it by uncovering previously indecipherable (but ultimately nonsense) clues. It’s slow to get started, and fails to engage. If you can switch off and not worry too much about how coherent the investigation is, then you can probably get something out of the performances. Otherwise, I’d pass on this film. (See my Girl With The Dragon Tattoo Twitter review).

Finally, I Love You, Phillip Morris is a real wasted opportunity, from what seems like it could be a genuinely brilliant story about a conman who will go to great lengths to get what he wants. Instead we have a movie that sits between flimsy comedy and feel-good movie, but never really reaching either. The central relationship between Jim Carrey and Ewan McGregor never feels convincing or genuine, needing more time to develop than the few moments we are given. The film desperately needed a longer run-time in order to show more development. Here’s a hint: if you have more than one montage (I think there were at least 3-4), you need a longer movie. A real shame, as it would be good to see Carrey do another serious film. (See my I Love You, Phillip Morris review).

The winner this month is Crazy Heart, mostly for the fantastic performances by the central cast and despite the short final act.

« Older entries