Archive for April, 2007

Maven: The Definitive Guide

Sunday, April 29th, 2007

I’m a big fan of Maven and have considered writing a book on Maven2, however that’s not necessary now as Jason Van Zyl has posted his book, Maven: The Definitive Guide. It’s almost complete and when I’m finished reading it end-to-end I’ll post more comments, but since good Maven2 information is hard to find I’m posting now. There is also a downloadable version of the book.

Please give it a read and send your feedback to Jason.

The most amazing game ever …

Sunday, April 22nd, 2007

I have been waiting for the game incrysis to come out for some time. It looks simply amazing as this video can attest.

I’m going to upgrade to whatever is required to play this game to it’s full potential. Now if the virtual worlds out there looked like this then I’d be tempted to hang around in them.

Humane Code

Sunday, April 22nd, 2007

I like “humane” code. Thats code that is expressive to the reader and the computer. “Humane” code allows messages like printOn: to be sent to objects like Account rather than requiring a service object to be used directly. I have a few posts here that deal with this topic in one way or another. Like this and this, however, a really good discussion which I think is related to the topic is here on the Cogent site.  There is also a realted article on the Object Mentor blog.

The discussion gets down to the heart of programming, the many ‘values’ associated with it and how code isn’t just for the computer. Please take a moment to read the discussion as I think you will be glad you did.

Team Tests …

Saturday, April 21st, 2007

I was asked to comment on Testing in general terms and what approach can fit most projects. What follows is my response, from a Java Test Driven perspective. I probably need clarification and some better words around this topic, but this is a start.

Think about the behavior you need to test. Make java interfaces to support the behavior as it will help with testing.

This can be top-down or bottom-up and which doesn’t matter, use the approach that best suits you and the goals and values of the project team.

If the behavior is UI based and you are thinking top-down then your most likely needing to start with an integration test. A tool like Salenium is good for this, although HtmlUnit/HttpUnit are also good.

A UI integration test can sometimes be confused with an interaction test since people think of ‘interacting’ with the UI. If the components that the UI integrate with are mocked out then I’d be inclined to call it an interaction test. There is no hard and fast rule and just make sure your team shares the same definition of terms as you.

If your testing the behavior of a single page and just the fixed parts of this page then you could see the test as a unit test. There is a fine and blurry line in this case. Unit test tools like junit, HtmlUnit/HttpUnit/jsunit in combination with jetty are good here.

When making a unit test for the behavior of a UI it is best to use Fixtures with your tests to encapsulate the UI in java classes, since our tooling supports classes best and changes to the UI can be localized into Fixtures and minimize change impact on other tests. I recently changed a core Fixture to use HtmlUnit instead of HttpUnit and in about 15 minutes all the tests ran again with the new underlying library.

When testing a single class in isolation then all the classes that the class under test interacts with should be mocked out. Tools like jmock and easymock are good here. This would be called an interaction test since the use of mocks will require specifying the expected interactions the class under test has with the mocked classes.

Sometimes you can’t test a class without using mocks and in this case the test is an interaction test even though no unit tests exist. When you make additional test cases with concrete components, these form integration tests, since your integrating one class with an actual implementation of another.

If a concrete class is ‘cheap’ to create and use then you don’t really need to mock it but it’s still a good practice to use it via a java interface.

When running tests the units should be tested first then the integration tests since these will rely on the tested units. This isn’t a strict rule and your approach depends on the continuous integration setup and should be organized to break the build quickly to make the test loop small and fast. Unit tests typically run quicker than integration and interaction tests.

At some point in the lifecycle of the tests all the parts should come together to represent the solution as it would be in production or as close as is possible and tested end to end. This can be slow and in some projects these tests are run as a separate ’slow-build’ since it’s not common for this build to break since it depends on the faster build which would have tested the units and integrated parts already.

There is no one-size-fits-all approach and each project should determine which approach and set of tools to use and stick with them until they are found not to support the goals and values of the project team.

Happy Testing.

code like an iPod…

Friday, April 20th, 2007

Today I caught the train to our client site and during the journey I noticed a lot of people wearing headphones. Of those people around me that I could reach out and touch, eight (8) of the eleven (11) had Apple iPods. One guy had his ear-buds jammed so far into his ears that I can imaging he will be saying “what?” a lot in later life, but thats getting off topic.

Marketing would account for some but not all of this sort of product / brand loyalty and the majority I think is from the experience engendered by the design of the product itself. It’s simple, good looking and it performs it’s function well.

We should try to endgender the same experience in the things we create and I do mean in the code we write and the products it goes into. I believe that the benefits from doing so will out-way the effort required to achieve it, and who knows, maybe your next piece of code, library or product will have as big an impact as the Apple iPod.

An Answered Prayer …

Tuesday, April 17th, 2007

For a long time I have had a love affair with Smalltalk, then a LISP person showed me how he wrote a Smalltalk method interpreter in about 10 lines of LISP, so I spent a lot of time reading on LISP. I have about 13 books on LISP in my library now.

LISP is probably the most simple and most powerfull language period. I adore it’s purity of syntax and function.  This comic says it all.
For a long time I have been wanting to write a version of LISP in C/Assembler but I haven’t really started as the thing holding me back was the fact that the world has gone Java and the possibility of Java environments moving to another environment or language looks remote. I think this is one reason why jruby exists but thats another post.

Enter jlispin, an implementation of LISP by Bill Birch the creator of reflisp done in Java. Bill is local (Melbourne, Australia) and a real LISP advocate and expert so I have high hopes for this LISP. Please check it out and support the project if you can.

Pimp my Abstraction ?

Friday, April 13th, 2007

I’ve been vexed by the question of where methods belong by fellow developers. I prefer a ‘humane’ organisation because I anthropomorphise objects when thinking about the behaviour they should exhibit. So a method like printOn(Printer) in a Person object makes sense to me since I can see myself asking a Person to write their details onto some media in block letters. The detractors of this approach suggest to me that a method like printOn(Printer) doesn’t belong in a Person object but a ’service’ object.

I’m not sure how a ’service’ object could achive the desired behaviour without violating some principles like information hiding and tell don’t and also still achieve an arrangement of objects where the cost of change is kept to a minimum.

Since I’m not sure how a ’service’ approach migh be implemented but I am sure how I would currently implement the ability to print a Person I have described the approach below, which I have cut down to a minimum to convey just the concepts.

Please let me know what you think of this approach and please let me know if you have a ’service’ like implementation you could share with me.

In my implementation a Person can print to any type of PersonPrinter.

// A Person class with the printing behaviour …
class Person {

// construction protocol …
Person(firstname, lastname, dateOfBirth) { … }

// printing protocol …
Person printOn(PersonPrinter) { … }

:
}

:

// An example of someone using the Person and printing them in
/ different ways …
Person me = new Person(”James”, “Ladd”, new Date(”09/09/1967″));
me.printOn(labelPrinter);
me.printOn(salutationPrinter);

:

// Object that a Person can print to …
class PersonPrinter {

void printFirstname(firstname);
void printLastname(lastname);
void printDateOfBirth(dateOfBirth);

:

// A variation of a PersonPrinter …
class LabelPrinter implements PersonPrinter {

void printFirstName(firstname) {
stream.print(firstname);
stream.print(” “);
:

// Another variation of a Person printer …
class SalutationPrinter implements PersonPrinter {

void printFirstName(firstname) {
stream.print(”Hi “);
stream.print(firstname);

:

The things I like about this approach are:

  • It’s very testable.
  • I can always make new Person Printers.
  • I can change the implementation of Person without effecting the ability to print one. ie: If Person dateOfBirth was changed to age I just change the way the printDateOfBirth() is called in one place.
  • Person can be immutable and I don’t have any getters/setters since they are not necessary.
  • There are other things as well.

A One-Click Agile Environment …

Friday, April 6th, 2007

I’m in the process of making a single-click download for an Agile Continuous Integration Environment, since I have set one up previously and now that I need another one it’s time to make it re-usable and simple. I’m hoping that eventually my employer Aegeon will host the download since it is a big one and because they use it.

So what’s an Agile Continuous Integration Environment I hear you ask. It’s a virtual machine image with Subversion, Continuum, Tomcat, Java etc and the Subversion Repository comes with a Maven 2 Project to check out and run. There isn’t anything really Agile about it but I find most projects that are Agile use this sort of environment.

The contained project has Eclipse with all the expected plugins and configuration. There’s Checkstyle, PMD, Findbugs, Complexian, Cobertura and Macker to name just a few. It’s also got Eclipse executables for Linux, Windows and Mac OSX.

The goal is to have a new CI environment or a new developer working in under 5 minutes. All you need to do is to run the VMware image with VMPlayer and configure a few things on the VM like where to send emails of build results. A developer does a Subversion checkout and the whole projects ready to go, including the Eclipse environment. Run ‘mvn install’ and that’s it, the developer is in a position to contribute.

The Maven2 project has separate files run for test and integration-test phases, and the web app is tested with httpunit for unit tests and Salenium for integration tests. A few of the requirements for the Maven2 project are contributed by Steve Hayes from this post.
The Maven repository is also contained within the project so there should be no downloads unless you change a dependency. All items are in the subversion repository for complete configuration management. Tomcat is in there too and it’s deployed automatically when needed. Jetty is used for inline container needs.

I have worked on extending the default Maven2 site generation and this includes going to Jira for change information, collating todo lists from the code, building an FAQ and more. When I get time here will also be a maven plug-in for Complexian but initially this will use the antrun facilities in Maven.

I’m keen to know what else should / could be in there so please let me know?

JavaScript is the new black …

Tuesday, April 3rd, 2007

JavaScript is a very powerful language and the more I use it the more I see it’s power. It’s very LISP like with its use of associative arrays to manage objects and it’s use of functions as first class objects.

In JavaScript you can create a new function and associate that function with a variable. When a function is invoked with ‘new’ then the result is an object. For example:

// assign a function to a variable.
var func = function(x,y) {return x + y;}
// create an object
var point = new Point(x,y);

An object can have functions added to it at runtime. We call these functions methods since they are associated with an instance and have access to the variable ‘this’.

The function object has access to the arguments to the function as an array. So you could iterate through the variable list of arguments and take an appropriate action. For example, you could convert each parameter into a method call on the object and call it. Very powerful.

For a quick and cheap reference to what JavaScript can do I recommend the book JavaScript Pocket Reference by David Flanagan (2nd Edition) from O’Reilly.