January 8, 2006

Show me the money

The (state) school that my children attend would benefit from more money.

I am offering to do a day's consulting (which could include, for example, running one or more of my tutorials, workshops, or a retrospective), for a donation to the school (it has it's own charity set up).

What you get in return

My "speciality" is Agile/eXtreme Programming (XP): my PhD was in refactoring (completed 1996), I wrote Jester and MockMaker. I've presented lots of tutorials and workshops on Test Driven Development (TDD) and Refactoring. I've been working in an Agile/eXtreme Programming (XP) way for many years. I've got a lot of experience as a coach, developer or team lead in lots of XP teams and projects. See my web site for more ideas of how you might get something out of me for a day.

The Rules

The "rules" are that the company cannot be a current ThoughtWorks client. Donations will have to be made to the school directly (not via me). If more than one company is interested then I will decide who to work for based on the proposed donation, what you want me to do and where you are located. You will have to pay any travel and accommodation costs. Unless the donation is huge, it will have to be within 4 hours travel time of London, England. I will have no control over how any money is spent.

Contact me

Please email me (ivanteam at tadmad.co.uk) with how much you'll donate for my day of consulting (or ask me how much I suggest you should donate), what you're interested in me doing, and roughly when you'd like me to do it, before 31st January 2006. I won't pass on any details of any enquiry to anyone. If you are interested but would like more time, then please email me about this before 31st January. I might blog about what I end up doing, but only with your written permission.

Posted by ivan at 6:41 PM Copyright (c) 2004-2007 Ivan Moore

January 4, 2006

Java 5.0 annotations

I've finally got around to looking at some of the new features in Java 5.0. When Java 5.0 first came out, it seemed like the new features were mostly Java (ironically) catching up with C#. (BTW - my background includes several years of Java, then some C#, then some more Java, then some more C# and currently Java again).

What I've seen so far looks good, but there are some things that I'd have preferred to be slightly different. This article is about Annotations, and I might write future articles on other of the new features in Java 5.0.

Annotations allow you to add metadata, examples include object/relational mapping and specifying test methods. I won't go into details here - just a simple example (it's left to the interested reader to find out more).

Defining an annotation type

To define an annotation type called Meta:

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Meta {
	String data() default "fast";
}

Using an annotation

To use that annotation:

...
	@Meta(data = "slow") 
	public void foo(){
...
	}
...

Using the annotation meta data ("calm down dear, it's only an example").

To print out the meta data that the annotation defines for the example above:

	public static void main(String[] args) {
		for (Method method : MyClass.class.getMethods()) {
			Annotation[] annotations = method.getAnnotations();
			int num = annotations.length;
			if(num==1){
				System.out.println(((Meta)annotations[0]).data());
			}
		}
	}

@Retention Gotcha

When defining an annotation type, you can specify when the annotation should be available; in a nutshell, before compilation (RetentionPolicy.SOURCE), after compilation (RetentionPolicy.CLASS) or at runtime (RetentionPolicy.RUNTIME). The default is RetentionPolicy.CLASS - not what I would have expected. My guess is that the main use of annotations will be for metadata that you want available at runtime, and certainly the examples that I've seen so far are nearly all runtime.

Syntax Gotcha

The fact that the syntax looks so similar for an annotation type compared to an interface - only an "@" different - I think is more confusing than helpful. An annotation type cannot extend or implement anything. The "attributes" (things that look like method declarations) cannot have parameters. Also, as you can see from the example above, annotation types implicitly, rather than explicity, implement "Annotation".

Posted by ivan at 4:53 PM Copyright (c) 2004-2007 Ivan Moore