Jamie's Space

JP

Quick Update on Unit Testing

Just thought I would add one more blog post to the millions of others floating around the net about how great unit testing is. I’ve spent the last week or so designing and implementing a cleaner version of one of the major modules of ArchAngel, and I couldn’t have done it without the regression test suite I wrote. It picked up all of those tiny little bugs that you just look over, but will cause you massive grief later on because they exist in parts of the code that “should just work”.

The number one lesson I’ve learned from this is to never assume anything works, even very simple things.

I started reading Pragmatic Unit Testing in C# with NUnit (http://www.pragprog.com/titles/utc2/pragmatic-unit-testing-in-c-with-nunit-2nd-ed) a few days into the design phase, and although I was doing some unit testing it pushed me into implementing more and better tests. It is a really good introduction to both how to unit test, as well as what to test. I highly recommend it for anyone working in C#. They have a Java/JUnit one there too, but I haven’t read that one.

In short: Unit testing saved my sanity this week.

Contracting Experiences So Far…

The first thing I did before collecting any money was set up a separate bank account. I got another Fast Saver, which is currently offering 7.75% interest per annum. This way I can earn a little interest on my tax before I have to pay it out at the end of the month.

At the end of last week I sent out my first invoice, and received my first bill payment. I used the online PAYE calculator at PAYE Calculator 2008 to calculate my income after tax. I then removed that amount from the business account, leaving the PAYE and GST in there for later payment. This means there is no chance of missing a tax payment, as I have kept the money aside.

I’ve also been printing out everything (invoices, tax calculations, bank statements showing income and payments) and putting it aside. This should make it easier for me to organise everything when it comes time to pay my taxes. I have asked an accountant (a very helpful family friend) for a bit of advice as to what I should be doing too, and he is doing a bit of research for me.

On the actual work front, everything has been going great so far. Gareth has been very helpful in getting me up to speed on the code base. I’m currently working on a formatter for TSQL code. I’ve written a bunch of new code, as well as refactored old code to make it easier to modify. I am also creating a unit test suite to make sure I don’t break anything. My next major task is to incorporate a whitespace insensitive text diff into our tests - this way I can run the code through the formatter and make sure it hasn’t removed anything important. Since there is a huge amount of TSQL code to work with, I can just run the formatter over it and throw the before and after code at the diff. If anything gets broken, the diff will pick it up.

Playing With ANTLR

Today I started doing some research on ANTLR (http://www.antlr.org/), a very powerful parser generator. It compiles language grammars into source code for a number of languages (I am working with C# output mostly, but it primarily creates Java). I am currently learning about Abstract Syntax Trees (http://en.wikipedia.org/wiki/Abstract_syntax_tree) and how I could use one of those instead of a Parse Tree (http://en.wikipedia.org/wiki/Parse_tree), which is what I have previously been working with when parsing languages. The major difference is I need to modify whatever language grammar I am using so that it produces an AST. I am hoping this isn’t too difficult, but we will see how things go over the next few days after I get up to speed on ANTLR. So far it looks promising though. I am impressed with how powerful ANTLR is - because it produces source code, you can embed code in the language specification itself. It looks like it is going to be a bit of fun figuring this all out :-)

Registering for GST

Today I registered for GST using the online form at the IRD website (https://www.ird.govt.nz/cgi-bin/form.cgi?form=ir360) after calling the IRD the other day and asking for a bit more information (they sent me some booklets). This was relatively painless, but necessitated by the fact that I am collecting GST from Slyce on my invoices. The good thing is you can apply to file every six months, which means I don’t have to worry about it for a while. They also say they might get in touch with you to give you a bit of advice on how to file a GST return. Which sounds pretty good to me.

Another thing I thought about today is ACC. It seems as a self employed person they calculate my ACC levies from my IR3 tax return at the end of the year. So I get stung with more bills around tax time. One thing I need to ring them and ask about is what happens if I stop being self employed half way through the year. Hopefully this should be just a case of ringing them and telling them when the time comes.

Joining the Wonderful World of Contracting

Today I was offered a contracting position with Slyce (http://www.slyce.com), a start up working on an amazing looking code generation tool. It allows the use of generated code without interfering with the ability to modify these files. Each file can be modified at will, and ArchAngel (http://www.slyce.com/ArchAngel/) will be able to reconcile those changes with any that it makes should the project be regenerated. I encourage you to read more about it - there’s not a lot of information about it on the website currently but that should change soon.

Expect to see a few posts dealing with the issues related to working as a contractor - I have to pay my own taxes and what not so I will try to detail how I went about the process in the hope that it proves useful to someone else.

Architecture Chat

I went along to the Sylvia Park Architecture Chat (http://wiki.bittercoder.com/Default.aspx?Page=SylviaParkArchitectureChats) yesterday in order to have a chat with some of the guys. It was great, I love talking (and listening) to other developers in a social setting. The chat is basically a way of getting a bunch of developers together to talk about things they have experienced lately, and discuss issues with like minded people. They have a focus on .Net, but some of the topics are applicable to other spaces as well. I highly encourage everyone to go along, it is well worth the time!

Maven Support in Netbeans 6.0

Today I started writing the message exchange beans for my ServiceMix/virtualisation benchmark. I have previously used Netbeans to develop these, but it usually requires manually adding the library JARs from the ServiceMix directory (plus any others it depends on) which is a bit of a pain.

Not so anymore! I installed the Maven plugin for Netbeans when I first installed it, with the intention of trying it out. While I was trying to add the java source directory of the bean service unit I am developing I noticed that the directory was showing up as a Netbeans project (they have a different icon to regular directories in the Netbeans file dialogs). I opened it up as a project instead, and it gave me a project with all of the library files added, the ability to modify parts of the POM using a form, easy access to sub-projects (if you open the root project up first), easy access to resources, the works. I am so impressed with this.

It even gives you the ability to execute any Maven goal from within Netbeans. This is great - usually when developing things for ServiceMix I have a number of windows open (Netbeans, a few command lines, explorer, notepad++, etc) and things get very cluttered. Now I can set up Maven actions in Netbeans that clean, install and deploy my service assemblies, without needing to switch between windows.

XSLT META Tag Output

My previous problem where the XSLT processor was outputting an unclosed meta tag has been solved. The W3C XSLT spec specifies that the processor should not output a new meta tag if there is one already present. Thus the way to fix the output so it did not add a meta tag was to insert one myself. However there are a few things to note. It will only do it within an html element that has the xhtml namespace. Also, if you do not have a trailing space before the closing / it will not work. See my example below (note I tried to use include-content-type=”no” which may or may not have worked. It takes a while to recompile and deploy the service-unit so I haven’t tried it):

<xsl:output method="xhtml" include-content-type="no"/>  
<xsl:template match="result">  
<html xmlns="http://www.w3.org/1999/xhtml">  
  <head>  
  <meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
  ...

Distributed ServiceMix Project Now Working

The tutorial app I wrote is now working. There were a few different problems. Firstly, I had removed some information about the secured broker in servicemix.xml and replaced it with a single flow name in a container attribute. I had forgotten about this until I reloaded the config from the distribution. Secondly, I needed to set up multiple static network connectors in activemq.xml, not a single one with multiple I.P. addresses. If put multiple I.P. addresses in a single static() block it will pick one at random and try to connect to it, doing this until it finds a working one then stopping. What is needed is multiple networkConnector elements with a single I.P. address in each static() block. I didn’t initially know how to do this because if I put two in it would give me an error. This leads to the next point. Thirdly, each networkConnector element needs a unique name (within the broker). So I gave them a name attribute corresponding to the ServiceMix instance they were connecting to. Fourthly, messages from the HTTP consumer service unit cannot be delivered to an endpoint on another ServiceMix instance (at least in my experience). I will post this to the mailing list later to see if there is a reason for this. Fifthly, and most importantly, ServiceMix 3.1.2 just plain does not work in my configuration. Upgrading to 3.2.1 fixed this and everything finally works. Well, except for my XSL transformation. They must have upgraded to a newer version of the XSLT processor (or used a different one), because it now ignores the directives I gave it telling it not to put unclosed tags in because it does that now, even in XML output mode. My root element is an so it may be overriding the xsl:ouput element (which it shouldn’t). If the XSL transformation does not output valid XML (which requires all tags to be closed) then ServiceMix cannot pass the HTML back to jetty to display to the user. This is my next task.

Broken Motion Sensor in My Wii Controller

Our flat has been playing Resident Evil 4 on the Wii together (well, one flatmate plays and we all watch and ‘advise’). Said flatmate dropped the nunchuck on the ground mid game and somehow broke the motion sensor in the remote. This resulted in the character constantly swiping their knife, making the game unplayable (you couldn’t even move). After a quick google search I came across a forum thread where someone had also broken their remote, and one person suggested tapping it quite hard on the back. This fixed mine, and after playing Wii Sports for a bit I can safely say it is fully functioning. That saved me $100, so I thought I would post it here on the off chance that it helps someone else out.

Update:

Just in case anyone was wondering if I ran into problems with this later, the controller is still fine.