Java

Guicing Struts 2

Look how deceptively easy the Guice User Manual makes adding Guice to a Struts 2 app appear. Look, it says, just add one jar and all your dependency injection needs will be meet. Of course what it fails to tell you is that in addition to adding the plugin JAR, you also need the base jar, the servlet jar and if you want it to work you need to download a fixed plugin jar. At one point it was moaning about commons-logging as well!

With all that done though, it does indeed work as advertised.

Standard
Macbook, Software

Music for the Mac

When I switched to OSX I was surprised to find that the “just works” system had no support for Ogg or FLAC. I also missed the simplicity and power of programs such as CDEx and MusikCube. I have had a look at all kinds of replacements but recently I was delighted to find a two programs that fill exactly the same niche on OSX. Max is a ripping program with a more elaborate interface than CDEx, this makes simple ripping a little more involved but it is possible to set up different encoding outputs for each rip so that once the track has been ripped it can then be encoded to different formats. You could produce a lossless FLAC version and a radio quality MP3 version for a small flash player. I haven’t been able to produce different encoding settings for the same output format and I am not sure that is supported.

Of course having encoded the music you also need something to play it on and finding a decent player on OSX is hard due to the smothering presence of iTunes. Cog is a player with a lot of features and decent format support that has a clean and simple interface. It is now my player of choice on the Mac and I would highly recommend it.

Standard
Java, Software

XWiki

I downloaded XWiki and gave the standalone application a whirl. I’m in the market for a simple wiki, I have used JSP Wiki before and it is fine but it can be a pain to setup correctly and I would also need to figure out how to secure editing offline first (as this is meant to be a public-read, private-edit wiki). My first impression is simply one of sluggish performance. It has a lot of nice features and it does arrive locked down but viewing and editing the pages is very lethargic and the Ajax is painfully slow. This could be the server but other servers are proving snappier.

Interestingly it seems to create a database in memory and import/export the data to file on startup/shutdown. I’m not sure what the advantage of that is, it seems counter-intuitive. Looking at options for a standalone database I am unsurprised to find a not saying that Hibernate does not play well with Derby. The lack of support between products built for either Derby and HSQLDB is annoying and seems unnecessary. However from past experience I know not to try and swim against the tide on this. If the developer worked exclusively on one or the other than chances are it is going to work better with the intended platform.

I also spotted a release note about a bug that requires Tomcat Security to be switched off. That doesn’t seem to be something you want to ship with. It’s not exactly the way you play with others.

Standard
Celeb Spotting, London

Paul Whitehouse and Charlie Higson

Wandering past the Almeida, side by side, like they were friends in real life. Higson had a white paper bag, which given the location and the improbability that he was out seeking a crafty afternoon kebab suggests a bite to eat at Ottolenghi. There is a certain odd couple quality to them, Whitehouse slightly brash and London; Higson diffident, quiet, very well-spoken. Both smartly dressed and not short a bob either.

Spotting them together must be extra points. Weird trivia: I am one of twenty people who have actually read Higson’s novel Full Whack. It is gruesome in parts, strange in others and is the only book I have read that features a dash along the M4 through Wales during which all narrative momentum is lost.

Standard
Java

Build it

This is a brilliant article that I have been using all last month on my work projects and it is both immensely powerful and very practical. It has made testing much easier and saved a phenomenal amount of time. However Nat doesn’t quite explain fully why it is so brilliant. What I have found is that once I have configured a Builder then actually I tend to use the same base object with minor alterations. If I am testing a sales catalogue for example and I want to have a test chocolate bar, then chances are I actually want three or four of them, all pretty much identical except for an id code and name. Using this technique makes it a doodle to knock out several objects in as many lines.

When I started I was conscientious about trying to provide a readable and complete API, later I realised “why bother?”. You need to find some sensible defaults for the necessary fields in the object but once you have you only need to implement the API surrounding the testing you are doing. Once you realise that then you get faster again. A lot of my work involves refactoring an old application and I am constantly surprised how few fields are actually used in the various beans and value objects. Often if you supply the “key” fields (the uid and anything else unique) then nothing else matters.

Standard
Java

Upgrade everything now

Okay so having got my PC working I foolishly did two things. One I tried to resize my disk partitions (hey in 2003 10Gb was all I would ever need for the C: partition), two I tried to re-install Windows XP after a house move. I got XP to install but couldn’t find my license key. So I decided to bite the bullet and buy Vista Home Premium instead and just get everything done in one go.

So Vista arrived this morning and this evening I stuck in the USB external DVD drive I use and… heard the DVD drive grind uselessly on the DVD for a while. Quickly chucking in a normal DVD I confirmed that that wasn’t a problem and headed over to Microsoft support. In the advice about unrecognised media it mentioned checking Firmware revisions on DVD players. Well, so be it, after all the drive is a couple of years old now, and so onto the Samsung website. They have a little updater program, that only runs on Windows… so now I am going to have to take my external DVD drive into work along with the Vista disk. Try the firmware upgrade with the disk and order CD copies of Vista if it still doesn’t work. Why should I do the latter? Well because Microsoft’s site for ordering alternative media doesn’t work with Firefox.

How come some many tech problems can only be solved by having a working platform in the first place?

Standard
Java

The Agony of being a PC Home Builder

My PC did not survive my housemove. When I booted it the BIOS screamed that there was a processor fault and that the gig was up. Dismantling the motherboard revealed no obvious faults or damage with the system but there it is; the PC was not going to boot. So one postal strike and shorted order later a new Intel Dual Core and Asus P5B-Plus (Vista Edition) arrive. With the normal sense of dread associated with assembling and dissembling PCs I set to work this weekend. I marvelled at how easy the new clip together processors and heatsinks are to installed. I worried that I’d screwed the memory by accidentally installing backwards and then I screwed the assemblage back together and thumb-screwed the case into one piece. Having completed I actually thought the whole experience wasn’t so bad. Buying an expensive Coolermaster case certainly made assembly easier than it had ever been and the rest of it was mostly clipping pieces together.

So I decided to boot, first boot works okay and I get to Windows but I need to set the BIOS to it’s defaults and I can’t use any port on the back of the motherboard. So I reboot, enter setup, hit the defaults and then restart. And I get a very cryptic error message that says Intel CPU uCode error. That’s it. Apart from a message that says “F1 to resume”. When you press F1 it reboots and does the same thing. Woe begins to fill my heart and tears creep into the edges of my eyes. What the hell is this about?

Well Googling didn’t really explain much other than people who bought the Asus P5B motherboard often have this problem and it is related to the processor. Every post recommends a BIOS flash. This is a brand new motherboard, sold as being Vista compatible, with an E6550 Intel processor which is listed as being compatible with the board. Why the hell do I have to flash the BIOS just to make the damn thing work?

There is however little choice; surveying my options I can create a bootable floppy; if I had a floppy of course, or a disk drive. Thankful this being the new millennium and all motherboard manufacturers have realised that perhaps people are not stashing obsolete hardware away in case they find a manufacturer unable to ship a motherboard which allows to use one of the most standard processors to have hit the market in years. So instead you can use the USB flash drive update.

This involves: downloading the ROM image, unzipping it to your flash drive. Sticking the drive into a functioning USB port (in my case my USB bracket was fully functional), then booting. When you hear the beep press the Del key. Then hit Alt + F2 before the BIOS boot trainwrecks on the same uCode problem. With that done you should be in the EZ Update program. Select your USB drive from the DOS-like menu and select your ROM image. The application will then read and verify it and you can zap your BIOS and get on with wondering why Creative’s MediaSource software doesn’t recognise the Creative soundcard you just installed when everything else sees it just fine thank you.

As you might have guessed finding the right BIOS flashing process took some trial and error. Seriously ASUS UI guys, what was happening at the meeting where you decided that the way people should access your new “easy” flash utility would be to hit Del, followed by Alt + F2 in quick succession? All of which has to be done exactly as otherwise you have to hit the reset button and kick off the process again.

These kind of problems make you wonder why you ever bother putting together your own kit, why not just leave the agony to Dell?

Standard
Groovy, Java, Scripting

Groovy Experiences

So I tried to implement one of my little Swing Utility ideas this weekend in Groovy. I need the utility and I thought it would be good to give the scripting language a go beyond simply using it as an interactive console onto the Java SE API. This is what I have learnt so far.

Well first off having an IDE helps. I used Smultron on OSX as it is an open source editor. Usually I use Komodo Edit for scripting and man have I become lazy about closing my brackets and braces. Probably the number one issue with my syntax.

I like to have a book to hand when learning a new language and in this case I have been using Groovy In Action. It is a good book and certainly seems to fulfill the role I have when learning something new. It is concise enough to allow me to jump to a particular topic when stuck on a particular point but also seems to have been written in enough of a structured narrative to give a context to what is going on when you are more particularly stumped. I would recommend it if you are looking for something similar.

Groovy doesn’t have the easiest error messages to understand. For example this foxed me for a bit:


links.each {
link -> if(link.startId = anId) { items.add(getItemById(link.endId)) }
}

The error message is:


org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, /Users/rrees/Documents/dev/groovy/MindField.groovy: 37: expecting ')', found '=' @ line 37, column 28.
link -> if(link.startId = anId) { items.add(getItemById(link.endId)) }

However the error is that I am trying to assign a value in an illegal location. It’s that old classic of = versus ==.

When an error blows up the stack trace is huge and this can be extremely distracting when, for example, a unit test assertion is failing. Since I am on the command line at the moment this is unavoidable but it also happens on the console and rapidly you need to clear the console before the next run. I think the console should definitely collapse the stack trace so you see the Message of the exception and then expand the stack trace when you want to see it. Often the Assertion Message is all you need.

Talking of unit tests, I needed them more than normal because while Groovy is very similar to Java there are enough differences to make it important that you double-check your assumptions. Not using equals once was a bit weird for example. Also Groovy arrays seem to differ from the Collections API safe-zone. GArrays are like Lists but don’t seem to support the List interface, no isEmpty for example. list.get(0) doesn’t get you the first element, list.getAt(0) or just list[0] does. Most collection interaction seems to be modelled after Ruby in that you have to get with the closures to do stuff. For some reason I found it difficult to get what I wanted out of the closures in one pass and I tended to get something working with the unit test and then shorten the closure to something concise.

Ruby closures did not seem this hard but maybe it was because the whole language is new on me. As Groovy allows you to bring over the Java idioms you are used to perhaps there was impedance between something that felt familiar but actually required a different approach.

My closing experience was another positive, Groovy’s XML and Swing Builder objects felt incredibly powerful and easy to use. The syntax is tough to grasp but being able to play around with it in the console helped. Swing Builder in particular feels like it could be the way you should make all Java Swing apps.

Overall it is a pretty positive experience. In term of the competitors it felt much more familiar than JRuby but the result was not as neat as Jython scripts tend to feel.

Standard