<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="text">Solitude</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/solitudevkps" /><subtitle type="text">Technology. Code. Living relentlessly in the real world.</subtitle><updated>2010-07-06T13:30:38+00:00</updated><generator uri="http://wordpress.org/">WordPress</generator><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="solitudevkps" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><id>http://solitude.vkps.co.uk/feed/atom/</id><entry><title type="html">Modern Java: The Point</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/07/06/modern-java-the-point/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-07-04T16:12:38-07:00</updated><id>http://solitude.vkps.co.uk/?p=1341</id><summary type="html">In the Modern Java series, I&amp;#8217;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 [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/07/06/modern-java-the-point/">&lt;p&gt;In the Modern Java series, I&amp;#8217;ve looked at how &lt;a title="Modern Java: Lombok" href="/Archives/2010/04/05/modern-java-lombok/"&gt;Lombok&lt;/a&gt; removes boilerplate from bean classes, &lt;a title="Modern Java: Validation" href="/Archives/2010/04/11/modern-java-validation/"&gt;JSR-303 validation&lt;/a&gt; makes checking domain correctness neat and how &lt;a title="Modern Java: JPA" href="/Archives/2010/04/22/modern-java-jpa/"&gt;JPA&lt;/a&gt; provides a convenient standardisation over the ORM space. Each of these technologies does something interesting and in an interesting way.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;No, the point of this series was multi-faceted, and I&amp;#8217;d like to take another few moments to try and explain what I was trying to achieve.&lt;/p&gt;
&lt;p&gt;Firstly, the primary concern for designing good systems is understanding the domain of interest. If you don&amp;#8217;t understand the domain well, you won&amp;#8217;t be able to produce a nice user experience at the front-end. You won&amp;#8217;t be able to write meaningful abstractions at the back-end. You won&amp;#8217;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 &lt;em&gt;prerequisite&lt;/em&gt; for good design.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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&amp;#8217;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&amp;#8217;m sure it could be quite neat, I can&amp;#8217;t imagine a solution quite as neat as the one offered by the technologies I mentioned.&lt;/p&gt;
&lt;p&gt;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&amp;#8217;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 &lt;em&gt;am&lt;/em&gt; 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.&lt;/p&gt;
&lt;p&gt;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 &lt;a href="http://openjdk.java.net/projects/coin/"&gt;Project Coin&lt;/a&gt; and &lt;a href="http://openjdk.java.net/projects/lambda/"&gt;Project Lambda&lt;/a&gt; improvements due in Java 7 later in the year, I really think this will be the case.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><title type="html">Film Fight 2010: June</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/07/04/film-fight-2010-june/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-07-04T15:20:01-07:00</updated><id>http://solitude.vkps.co.uk/?p=962</id><summary type="html">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&amp;#8217;s all-sorts of [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/07/04/film-fight-2010-june/">&lt;p&gt;Three new films this month, all quite different.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Rec 2&lt;/strong&gt; picks up immediately after the ending of &lt;a href="/Archives/2008/07/04/film-fight-april-2008/"&gt;Rec&lt;/a&gt;, 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&amp;#8217;s all-sorts of terrible tell-don&amp;#8217;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 &lt;a href="http://twitter.com/garyfleming/status/15340433017"&gt;my Rec 2 Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Killer Inside Me&lt;/strong&gt; is, if nothing else, beautifully shot with art-direction in the opening credits that most films can&amp;#8217;t muster in 90 minutes. The look throughout is striking, whether we&amp;#8217;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&amp;#8217;re extremely powerful and shocking moments, they sit amongst a plot that for the most part lurches along and doesn&amp;#8217;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&amp;#8217;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 &lt;a href="http://twitter.com/garyfleming/status/15659114490"&gt;my The Killer Inside Me Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Finally, &lt;strong&gt;Shrek Forever After&lt;/strong&gt; marks the supposed end of the series, with Dreamworks claiming they won&amp;#8217;t make any more. I wish they&amp;#8217;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&amp;#8217;t have noticed the difference. Okay, but not great.  (See &lt;a href="http://twitter.com/garyfleming/status/17194132498"&gt;my Shrek Forever After Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;While I didn&amp;#8217;t think any of the films this month were particularly great, the winner is &lt;strong&gt;Rec 2&lt;/strong&gt;. Despite a fairly nonsensical plot, it delivered where it mattered: providing a horror-filled, cinematic experience.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><title type="html">Film Fight 2010: May</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/06/21/film-fight-2010-may/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-06-21T11:35:21-07:00</updated><id>http://solitude.vkps.co.uk/?p=960</id><summary type="html">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 [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/06/21/film-fight-2010-may/">&lt;p&gt;It may be a few weeks late, but the Film Fight for May is an extremely light one with only one film.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Four Lions&lt;/strong&gt; 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&amp;#8217;s almost entirely silly, poking fun at the idea of the bombers and their ridiculous scheme. (See &lt;a href="http://twitter.com/garyfleming/status/13662546747"&gt;my Four Lions Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;And the winner is&amp;#8230; &lt;strong&gt;Four Lions&lt;/strong&gt;. Obviously.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><title type="html">Film Fight 2010: April</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/05/09/film-fight-2010-april/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-05-09T12:00:00-07:00</updated><id>http://solitude.vkps.co.uk/?p=954</id><summary type="html">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&amp;#8217;s an absurd premise (a kid decides to become a super-hero and finds out he isn&amp;#8217;t the first one to try it), that holds together remarkably well when paired up with intentionally over-the-top violence [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/05/09/film-fight-2010-april/">&lt;p&gt;A reasonably busy April at the cinemas has meant another bigger-than-usual Film Fight, with five films.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Kick-Ass&lt;/strong&gt; is a ridiculous film. It&amp;#8217;s an absurd premise (a kid decides to become a super-hero and finds out he isn&amp;#8217;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&amp;#8217;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&amp;#8217;t anything to right home about, and it has some cringeworthy moments, it remains entertaining to the end. (See &lt;a href="http://twitter.com/garyfleming/status/11537585568"&gt;my Kick Ass Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Green Zone&lt;/strong&gt; sees Matt Damon team back up with Paul Greengrass, in a plot pulled straight from a Tom Clancy novel. Yes, it&amp;#8217;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&amp;#8217;s previous super-spy character. Worth seeing. (See &lt;a href="http://twitter.com/garyfleming/status/11656294361"&gt;my Green Zone Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;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 &lt;strong&gt;Crying With Laughter&lt;/strong&gt; 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&amp;#8217;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 &lt;a href="http://twitter.com/garyfleming/status/12416359447"&gt;my Crying with Laughter Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Mike Judge has an incredibly strong legacy with Beavis &amp;#038; Butthead, King of the Hill, Idiocracy and his classic, Office Space. It&amp;#8217;s with that in mind that it&amp;#8217;s fairly surprising his new movie, &lt;strong&gt;Extract&lt;/strong&gt;, just isn&amp;#8217;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&amp;#8217;s not awful, but it is entirely forgettable. (See &lt;a href="http://twitter.com/garyfleming/status/12829983754"&gt;my Extract Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Finally, Todd Solondz returns to the characters he introduced in Happiness 12 years ago, recasting them all in a pseudo-sequel, &lt;strong&gt;Life During Wartime&lt;/strong&gt;. If you liked the first film, you&amp;#8217;ll wish he hadn&amp;#8217;t. It has a scant few jokes that hit the familiar territory of awkwardness that Solondz thrives in, but much of it doesn&amp;#8217;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&amp;#8217;s not much of a theme, just a series of moments that hang together poorly. It&amp;#8217;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 &lt;a href="http://twitter.com/garyfleming/status/13030912203 "&gt;my Life During Wartime Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;And the winner is&amp;#8230; &lt;strong&gt;Crying With Laughter&lt;/strong&gt;, for walking the fine line between horrific and funny extremely well.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><title type="html">Modern Java: JPA</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/04/22/modern-java-jpa/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-04-22T12:54:10-07:00</updated><id>http://solitude.vkps.co.uk/?p=952</id><summary type="html">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 [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/04/22/modern-java-jpa/">&lt;p&gt;In the previous post, I &lt;a href="http://solitude.vkps.co.uk/Archives/2010/04/11/modern-java-validation/"&gt;showed how JSR-303 is making validation neater.&lt;/a&gt;  I concluded that article with the Person bean looking like this:&lt;/p&gt;
&lt;pre class="brush: java;"&gt;
@Data
public class Person {
    @NotNull @Size(min=1)
    private String firstName;
    @NotNull @Size(min=1)
    private String lastName;
    @Min(18)
    private int age;
}
&lt;/pre&gt;
&lt;p&gt;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&amp;#8217;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 &lt;a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html"&gt;Spring&amp;#8217;s JdbcTemplate&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I also won&amp;#8217;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 &lt;a href="http://www.hibernate.org/"&gt;Hibernate&lt;/a&gt;) 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&amp;#8217;m going to have to add to Person):&lt;/p&gt;
&lt;pre class="brush: java;"&gt;
@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;
}
&lt;/pre&gt;
&lt;p&gt;And that&amp;#8217;s it. You can then use a properly configured EntityManager to persist() your class (the configuration details are largely implementation specific, but relatively lightweight).&lt;/p&gt;
&lt;p&gt;There are a lot of options available to configure exactly how an entity should be persisted when passed into an EntityManager. Again, I won&amp;#8217;t cover them all, but it&amp;#8217;s generally considered best practice to state your table and column names explicitly (rather than relying on convention, as I have above) and you&amp;#8217;ll often want to make use of the built-in optimistic concurrency support to stop multiple changes happening at once.&lt;/p&gt;
&lt;pre class="brush: java;"&gt;
@Data @Entity @Table(name=&amp;quot;people&amp;quot;)
public class Person {
    @Id @Column(name=&amp;quot;id&amp;quot;);
    private Long id;

    @Version @Column(name=&amp;quot;version&amp;quot;)
    private int version;

    @NotNull @Size(min=1)
    @Column(name=&amp;quot;first_name&amp;quot;)
    private String firstName;

    @NotNull @Size(min=1)
    @Column(name=&amp;quot;last_name&amp;quot;)
    private String lastName;

    @Min(18)
    @Column(name=&amp;quot;age&amp;quot;)
    private int age;
}
&lt;/pre&gt;
&lt;p&gt;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&amp;#8217;t have to explicitly call the validator any more.&lt;/p&gt;
&lt;p&gt;Again, there&amp;#8217;s a lot more to be said about JPA, and the use cases that it supports (I haven&amp;#8217;t touched on object-graphs, embedded collections, or the Java persistence query language), but you should have a flavour for it.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></entry><entry><title type="html">Modern Java: Validation</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/04/11/modern-java-validation/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-04-11T11:26:08-07:00</updated><id>http://solitude.vkps.co.uk/?p=944</id><summary type="html">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 [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/04/11/modern-java-validation/">&lt;p&gt;In the previous post on Modern Java, I showed how &lt;a href="/Archives/2010/04/05/modern-java-lombok/"&gt;Lombok is making Java beans more concise&lt;/a&gt;. In that post, I showed how we would end up with the following class:&lt;/p&gt;
&lt;pre class="brush: java;"&gt;
@Data
public class Person {
    private String firstName;
    private String lastName;
    private int age;
}
&lt;/pre&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;For example, if we assume &amp;#8220;age&amp;#8221; 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&amp;#8217;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).&lt;/p&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;pre class="brush: java;"&gt;
public Collection&amp;lt;Error&amp;gt; validate(Person person) {
  Collection&amp;lt;Error&amp;gt; errors = new LinkedList&amp;lt;Error&amp;gt;();
  if(person.getAge() == null) {
    errors.add(new Error(&amp;quot;Age cannot be null&amp;quot;));
  }
  if(person.getAge() &amp;lt; 0) {
    errors.add(new Error(&amp;quot;Age must be greater than zero&amp;quot;));
  }
  if(person.getAge() &amp;gt; 120) {
    errors.add(new Error(&amp;quot;Unlikely to be a real age&amp;quot;));
  }
  return errors;
}
&lt;/pre&gt;
&lt;p&gt;Note that we&amp;#8217;re only validating a few rules on one field, and it&amp;#8217;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.&lt;/p&gt;
&lt;p&gt;Both the &lt;a href="http://www.springsource.org/"&gt;Spring Framework&lt;/a&gt; and &lt;a href="http://hibernate.org/"&gt;Hibernate&lt;/a&gt; had come up with their own ways of making writing and integrating validation logic a little easier, but now validation has been standardised in &lt;a href="http://jcp.org/en/jsr/detail?id=303"&gt;JSR-303&lt;/a&gt;. The reference implementation is Hibernate Validator 4, and it&amp;#8217;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.&lt;/p&gt;
&lt;p&gt;For our Person class above, let&amp;#8217;s add the following constraints:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Age must be 18 or more&lt;/li&gt;
&lt;li&gt;First  and last name must be set i.e. they can&amp;#8217;t be left null&lt;/li&gt;
&lt;li&gt;First and last name must have at least one character in them&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To implement these rules, we need only add a few new annotations, using standard constraints:&lt;/p&gt;
&lt;pre class="brush: java;"&gt;
@Data
public class Person {
    @NotNull @Size(min=1)
    private String firstName;
     @NotNull @Size(min=1)
    private String lastName;
    @Min(18)
    private int age;
}
&lt;/pre&gt;
&lt;p&gt;You then create a Validator instance (how you do this will depend on your chosen implementation), and pass the class in for validation:&lt;/p&gt;
&lt;pre class="brush: java;"&gt;
Set&amp;lt;ConstraintViolation&amp;lt;Person&amp;gt;&amp;gt; errors = validator.validate(person);
&lt;/pre&gt;
&lt;p&gt;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&amp;#8217;s a very good thing.&lt;/p&gt;
&lt;p&gt;There&amp;#8217;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&amp;#8217;d strongly recommend browsing the spec to see some of the power and flexibility available to you.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></entry><entry><title type="html">Modern Java: Lombok</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/04/05/modern-java-lombok/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-04-05T11:55:26-07:00</updated><id>http://solitude.vkps.co.uk/?p=941</id><summary type="html">In recent months, I&amp;#8217;ve been looking at a lot of new Java libraries to see what I&amp;#8217;d like to use and what I think still has a way to go. I&amp;#8217;ll be posting about them all in due course but I wanted to mention Lombok first. First, a class: public class Person { private String [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/04/05/modern-java-lombok/">&lt;p&gt;In recent months, I&amp;#8217;ve been looking at a lot of new Java libraries to see what I&amp;#8217;d like to use and what I think still has a way to go. I&amp;#8217;ll be posting about them all in due course but I wanted to mention &lt;a href="http://projectlombok.org/"&gt;Lombok&lt;/a&gt; first.&lt;/p&gt;
&lt;p&gt;First, a class:&lt;/p&gt;
&lt;pre class="brush: java;"&gt;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;
    }
}
&lt;/pre&gt;
&lt;p&gt;The problem here is that everything after &lt;code&gt;public int age&lt;/code&gt; 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&amp;#8217;t the compiler take care of that for us rather than having us specify more code? Less code is often cleaner code.&lt;/p&gt;
&lt;p&gt;For several years now, people have been asking for the idea of &lt;a href="http://weblogs.java.net/blog/rbair/archive/2007/01/properties_in_j.html"&gt;properties in Java&lt;/a&gt;. 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.&lt;/p&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;pre class="brush: java;"&gt;
@Data
public class Person {
    private String firstName;
    private String lastName;
    private int age;
}
&lt;/pre&gt;
&lt;p&gt;That&amp;#8217;s right: the 18 or so lines of getter/setter boilerplate are replaced by the tiny little &lt;a href="http://projectlombok.org/features/Data.html"&gt;@Data&lt;/a&gt; annotation, and the code is much cleaner. As a bonus, @Data also generates a &lt;code&gt;toString()&lt;/code&gt;, an &lt;code&gt;equals()&lt;/code&gt; and a &lt;code&gt;hashCode()&lt;/code&gt;. You can use the other Lombok annotations to tweak the behaviour, but this is what most people are going to want.&lt;/p&gt;
&lt;p&gt;Also of note is the &lt;a href="http://projectlombok.org/features/Cleanup.html"&gt;@Cleanup annotation&lt;/a&gt;, which provides automatic resource management (ARM) for using input/output streams. While this will be less essential if ARM arrives in Java 7, it&amp;#8217;s a handy little helper for the time being.&lt;/p&gt;
&lt;p&gt;While Lombok can&amp;#8217;t make bad code good, it can make verbose code a lot more succinct.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><title type="html">Film Fight 2010: March</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/04/03/film-fight-2010-march/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-04-03T08:53:23-07:00</updated><id>http://solitude.vkps.co.uk/?p=937</id><summary type="html">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&amp;#8230; 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 [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/04/03/film-fight-2010-march/">&lt;p&gt;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&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Crazies&lt;/strong&gt; 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&lt;a href="http://twitter.com/garyfleming/status/9894174477"&gt; my The Crazies Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;A lot was expected of Tim Burton&amp;#8217;s foray into Lewis Carroll&amp;#8217;s classic novel, but &lt;strong&gt;Alice In Wonderland&lt;/strong&gt; disappoints. It&amp;#8217;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 &lt;a href="http://twitter.com/garyfleming/status/10122829856"&gt;my Alice In Wonderland Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Crazy Heart&lt;/strong&gt; 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&amp;#8217;ve completed this very worthwhile film a lot better. (See &lt;a href="http://twitter.com/garyfleming/status/10427696391"&gt;my Crazy Heart Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Martin Scorsese manages to show some great form with his latest work, &lt;strong&gt;Shutter Island&lt;/strong&gt;, 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&amp;#8217;s beautifully shot, if a little over-the-top in places. Leonardo Dicaprio pulls in a solid performance, but he can&amp;#8217;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 &lt;a href="http://twitter.com/garyfleming/status/10465887430"&gt;my Shutter Island Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Girl With The Dragon Tattoo&lt;/strong&gt; 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&amp;#8217;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&amp;#8217;d pass on this film. (See &lt;a href="http://twitter.com/garyfleming/status/10817443727"&gt;my Girl With The Dragon Tattoo Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Finally, &lt;strong&gt;I Love You, Phillip Morris&lt;/strong&gt; 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&amp;#8217;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 &lt;a href="http://twitter.com/garyfleming/status/10991752397"&gt;my I Love You, Phillip Morris review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The winner this month is &lt;strong&gt;Crazy Heart&lt;/strong&gt;, mostly for the fantastic performances by the central cast and despite the short final act.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><title type="html">Film Fight 2010: February</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/03/01/film-fight-2010-february/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-03-01T13:32:33-08:00</updated><id>http://solitude.vkps.co.uk/?p=935</id><summary type="html">It was a bit of a quiet month for me at the cinema, despite a lot of films that looked like they might be good being released. I only saw two films&amp;#8230; Youth in Revolt is a Michael Cera film, which should set up a number of expectations for it. You expect it to be [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/03/01/film-fight-2010-february/">&lt;p&gt;It was a bit of a quiet month for me at the cinema, despite a lot of films that looked like they might be good being released. I only saw two films&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Youth in Revolt&lt;/strong&gt; is a Michael Cera film, which should set up a number of expectations for it. You expect it to be a cute, indie-comedy about a geeky kid who has to find confidence to get the girl, or some other variation on the theme. The first act plays straight into this and is fairly weak for it. The middle, however, is substantially better as the lead character defers to his maniac alter-ego. Sadly, even this pretty funny section is ruined somewhat by the fact that 90% of it is in the trailer. While the ending isn&amp;#8217;t as strong, it&amp;#8217;s a fine finish to a watchable, but not great, movie. (Read &lt;a href="http://twitter.com/garyfleming/status/8732126616"&gt;my Youth in Revolt Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A Single Man&lt;/strong&gt; is a fairly straight-forward and somewhat predictable story of living with grief, through the eyes of someone who cannot allow themselves to express their feelings. The direction here is solid, bringing memories of Kubrick&amp;#8217;s shorter shots; dressing tables, desks, and lived-in spaces giving the feel of the characters in a few short seconds. Colin Firth puts in a fantastic performance as the lead, wavering between having a breakdown at any moment and keeping a stiff upper-lip. A very good film overall. (Read &lt;a href="http://twitter.com/garyfleming/status/9434205340"&gt;my A Single Man Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;While there wasn&amp;#8217;t much in the way of competition, &lt;strong&gt;A Single Man&lt;/strong&gt; is a well-deservied winner.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><title type="html">Film Fight 2010: January</title><link rel="alternate" type="text/html" href="http://solitude.vkps.co.uk/Archives/2010/02/02/film-fight-2010-january/" /><category term="Uncategorized" /><author><name>Gary Fleming</name><uri>http://solitude.vkps.co.uk</uri></author><updated>2010-02-01T15:05:47-08:00</updated><id>http://solitude.vkps.co.uk/?p=930</id><summary type="html">Another year, and another fresh film fight. As always, January was a tough month, with lots of pretty strong competition (usually the Oscar wannabes are released around this time of year). To get us started, there are 6 films this month. First up is Robert Downey Jr. in a role that he really wasn&amp;#8217;t born [...]</summary><content type="html" xml:base="http://solitude.vkps.co.uk/Archives/2010/02/02/film-fight-2010-january/">&lt;p&gt;Another year, and another fresh film fight. As always, January was a tough month, with lots of pretty strong competition (usually the Oscar wannabes are released around this time of year). To get us started, there are 6 films this month.&lt;/p&gt;
&lt;p&gt;First up is Robert Downey Jr. in a role that he really wasn&amp;#8217;t born to play: &lt;strong&gt;Sherlock Holmes&lt;/strong&gt;. Guy Ritchie gives us an interesting take on the classic detective. His typically non-linear storytelling is used to great effect to explain how the master detective has reached his conclusions, and is particularly good when he&amp;#8217;s sizing up opponents in fights, slowly and methodically showing how he&amp;#8217;s going to break down their defences. Why this particular story mechanic is dropped relatively early in the film is beyond me, because it&amp;#8217;s one of the strongest. Less good is the script: a fairly poor mishmash of ideas, ranging from secret societies, magic, steampunk and master villians. It doesn&amp;#8217;t particularly fit into the Sherlock Holmes mythos, and doesn&amp;#8217;t readily establish itself as a new take. It&amp;#8217;s a pretty mediocre action film, that&amp;#8217;s also trying to be a comedy. It fails to do anything particularly well. Not recommended.  (Read &lt;a href="http://twitter.com/garyfleming/status/7313858309"&gt;my Sherlock Holmes Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Daybreakers&lt;/strong&gt; is a surprisingly watchable, but not great, film. It deftly manages to build up its world, quickly, quietly and effectively, and moves on with the story it has to tell. This is a world where an infection has caused the vampires to take over and hunt down the humans. The vampires, however, have over-extended and food is becoming scarce. Queue a story about diminishing food supplies, the folly of rapid and mindless expansion, and a lot of gore. That&amp;#8217;s what saves this film: the tongue-in-cheek bloodbath we&amp;#8217;re treated with visually, paired with some slightly cheesy lines. The film would&amp;#8217;ve been better had it been more over-the-top. As it stands, Daybreakers is a decent action movie, but not a great one. (Read &lt;a href="http://twitter.com/garyfleming/status/7493111154"&gt;my Daybreaks Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Road&lt;/strong&gt; is the almost resolutely bleak, yet absolutely compelling. The primary narrative follows a father and son travelling through a post-apocalyptic world (what happened is never explained), as they encounter endless difficulties and enemies. What starts as trying to protect his son soon becomes a desperate paranoia, as the father becomes wary of everyone they met, and slowly loses his way. Several scenes are horrifyingly blunt about the lengths the father will go to to ensure they don&amp;#8217;t become food for the more cannibalistic elements, and Viggo Mortensen does a fantastic job of showing the slow decay that takes a grip of him. While the ending ties things up a little too neatly, the rest of the film is very well done. A must see. (Read &lt;a href="http://twitter.com/garyfleming/status/7597149764"&gt;my The Road Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Not many people would make a comedy about firing people, but Jason Reitman has done just that with &lt;strong&gt;Up in the Air&lt;/strong&gt;. The core conceit gives way to an inspection of the main character&amp;#8217;s choices in life at just the right time, showing him up to be a willing outcast and seeing if those choices are right. While it does veer dangerously close to schmaltzy in places, it always manages to pull away by being brutally honest elsewhere. It&amp;#8217;s not the funniest comedy, nor the best character piece, but both halves combine to make a good, solid movie. (Read &lt;a href="http://twitter.com/garyfleming/status/7862400594"&gt;my Up in the Air Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A Prophet&lt;/strong&gt; is a very interesting French film, a fairly gritty take on a prison drama. Malik begins as a young, somewhat naive hoodlum who goes to jail and, over the course of the film, becomes warped by his environment and the things he needs to do to survive. It doesn&amp;#8217;t pull many punches as he schemes his way further up the criminal ladder. It&amp;#8217;s well-structured and well-paced, being lent real weight by the very natural performances. While the scene in the middle where they both use the title and throw around a dead deer are puzzlingly unnecessary (and in poor taste), the rest of the film is very well done. (Read &lt;a href="http://twitter.com/garyfleming/status/8151079914"&gt;my A Prophet Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Finally, &lt;strong&gt;Precious&lt;/strong&gt; is a fairly harrowing story of bullying, abusive upbringings and never thinking you can make something of yourself. While, at times, it turns things around a little too neatly, the main plot-line is equally engaging and chilling. Mo&amp;#8217;Nique puts in an Oscar worthy performance as the abusive mother, handling a fairly dicey subject with a great believability. It&amp;#8217;s not easy to watch, but it is worthwhile. A powerful film. (Read &lt;a href="http://twitter.com/garyfleming/status/8414638989"&gt;my Precious Twitter review&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;And the winner? It was a close-run thing between Precious, The Road and A Prophet, but I think &lt;strong&gt;The Road&lt;/strong&gt; takes it in the end. Another great January for film.&lt;/p&gt;
</content><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry></feed>
