Category Archives: tech

My problem with Guice

I went to a presentation at my local Java User’s Group last Monday on Guice. I’m a long time Spring user (and fan), so I was interested to see what benefits it had over Spring.

I came away with the impression that Guice looks pretty interesting, but its main benefit over Spring is the lack of XML. That’s okay I guess (although I personally think the case against XML is often overstated). I certainly wouldn’t be opposed to using Guice in a project based on what I saw – except for one thing….

My big issue with Guice is the fact that it appears to be invasive. Based on the presentation I saw it seemed that you need to instrument your code with @Inject annotation for the dependency resolver to provide that dependency. That’s fine in your application code, but it means wrappers seem to be required for third party libraries. However, there are some hints from the documentation that this isn’t the case (‘Observe the Java type and the optional “binding annotation” of the element to be injected‘). OTOH, ‘sometimes you can’t use annotations, and you need to manually wire up an object (a 3rd party component for example). When this comes up, you write a custom provider‘ (See http://code.google.com/p/google-guice/wiki/SpringComparison). That’s kind of confusing, and something I’ll need to investigate more.

All in all – an interesting option, and one that certainly replaces PicoContainer as the best code-centric dependency injection container.

DWR Callback closures inside loops

I’ve been doing a fair bit of Javascript lately. Like anytime I learn a new language I look back at code I wrote a week ago and thing OMG… what was I thinking!?

One useful thing I learnt today was how to use the DWR closure callback pattern inside a loop.

My original code looked like this:


var taggedLinks = $$(".taggedlink");

for(var i=0; i < taggedlinks.length; i++) {
	RatingApi.getRating(taggedLinks[i].href, {
		callback: function(data) {
			displayRating(data, taggedLinks[i]);
		}
	});
}

Where RatingApi.getRating(..) is a DWR AJAX call. It’s fairly clear what the problem is: the displayRating function is called when RatingApi.getRating returns. Obviously the value of i will be not what was expected.

The solution looks like this (thanks Ben!):


var taggedLinks = $$(".taggedlink");

for(var i=0; i < taggedlinks.length; i++) {
	var remoteCall = {
		index : i,
		callback: function(data) {
			displayRating(data, taggedLinks[this.index]);
		}
	};	

	RatingApi.getRating(taggedLinks[i].href, remoteCall);
}

Sunshine disinfects.. unless you live in Australia

So I’ve been quite interested in the work TheyWorkForYou have been doing in the UK. It seemed like a good idea to do something similar for Australia – after all we have an election due soonish, and what’s another project to add to my list?

I figured that a good thing to start with would be to create some kind of API to give access to Member of Parliament’s financial interests. After all, it was only a few months ago when the former Federal Minister for Aging Santo Santoro had to resign over his financial dealings.

I was hoping I’d be able to find a page on the Parliament website which I could screen scrape and use as a data source for an API. After quite a lot of searching I was forced to send an email asking for help.

From that inquiry I found that neither the Senate nor the Representative’s Register of Pecuniary Interests is available online, or in any electronic form at all. The only way to see it is to physically go to Canberra, make an appointment and then copy the it which interest you.

As tempting as that sounds, I think I might start somewhere else….

Letting go of ideas

I'm something of an ideas person – I'm always full of great ideas to change the world (well – I think they are great anyway). For once, a few other people agreed that one of my ideas was worth pursuing, and it's actually looking like it might be implemented.

The thing I'm finding difficult is letting go – now my idea is out there and people are grabbing bits of it and discarding others and it's morphing into something that isn't quite what I thought up anymore.

It is an interesting process – I realize that logically some of their ideas are good, too, and I know that I can't do it all myself so I need their help. But…. letting people tamper with my idea is sometime painful. Hence I'm writing this entry to remind myself that what people are doing is good!

Tilting at windmills with an avalanche at your back

I often find myself in discussions with people who seem to truly believe that web standards somehow have an intrinsic value beyond the idea that they are a starting point for developing an application.

It can be quite a hard argument to make, since I'm not arguing that web standards are a bad thing in themselves, only that trying to support them at the expense of functionality is a mistake because simply supporting a web standard doesn't actually give any benefit in itself.

I was reminded of this argument today by Alex Russell of the Dojo toolkit who said:

Not accepting errors is suicide, and for too long the web standards community has confused validation and correct markup (things that reduce the number of people who can play in the sandbox) with the value created by agreement on how things should behave (things that increase the number of people who can use things that anyone creates).

His succinct way of phrasing that made me think of how I feel when I'm trying to make the same argument and hence the title of this post: I feel like making this argument is tilting at windmills, and yet those same windmills are being run over and swept away by the huge momentum of websites which actually work without any special effort in standard compliance, and by efforts like WHATWG who are following a much more pragmatic approach to standardization.

Random Observations on developer stuff

Random stuff:

  1. There's huge demand for (good) Java programmers. (Live in Adelaide, want a job & know Java? Contact me… Also, I'm still looking for an XUL person.)
  2. Javascript might be the next big language, and while everyone claims they can program in Javascript what they mean is that they know how to pop-up an alert box in a browser window. That isn't programming! (Live in Adelaide and know AJAX and possible a bit of Java? Contact me….)
  3. Spring is good.
  4. Doing estimates for a project when there are no requirements is difficult.
  5. Doing estimates for a (different) project when the functionality, resources and timeline are all fixed is very difficult.
  6. Social networking.. there's just too much to write on that topic.

XUL Developer Wanted

If you are an experienced XUL developer interested in working on a new, open source and potentially high profile Firefox 2.0 extension I'd be very interested in hearing from you. Realistically you are going to need to be located in Australia, and ideally in Adelaide.

Knowledge of accessibility and/or standards based web development would be an advantage.

To make it clear: This is a paid development position, but is only open if we can find the right person within the next few weeks

Interested? Contact me: nlothian at apache dot org as soon as possible.

Switched to Feedburner

I've switched my feeds at my BadMagicNumber blog to be published via FeedBurner. There should be no disruption to your normal programming, although I think some aggregators will show some non-new items as new.

I switched the feeds over using a simple Servlet Filter. If anyone wants to do the same, here's the code. This works for blojsom, but you might need to modify it slightly for your own setup.


public class FeedBurnerRedirectFilter implements Filter {
	private String redirectURL;
	
	public void init(FilterConfig config) throws ServletException {
		redirectURL = config.getInitParameter("redirectURL");		
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
						throws IOException, ServletException {
		String flavor = request.getParameter("flavor"); 
		
		if ("atom".equals(flavor) || "rss".equals(flavor) 
				|| "rss2".equals(flavor) || "rdf".equals(flavor) ) {			
			HttpServletRequest httpRequest = (HttpServletRequest) request;			
			HttpServletResponse httpResponse = (HttpServletResponse) response;
			
			String userAgent = httpRequest.getHeader("User-Agent");
			if (userAgent != null && userAgent.indexOf("FeedBurner") < 0) {
				/// redirect if not feedburner
				httpResponse.sendRedirect(redirectURL);
				return;				
			}
			
		}		
		chain.doFilter(request, response);		
	}

	public void destroy() {
		
	}
}