Archive for November, 2007

Nov 20 2007

Test Driven Porting

Published by under .NET,Bell Ringing,Programming

Recently I’ve had reason to take an code library written in C++ and port it to C#.  Whilst I dabbled in C++ on a compilers course at university, I hated it then and I still hate it now.  I personally think it’s an abomination and should be consigned to the great garbage collector in the sky.   Whilst I can just about read the C++ syntax there is a lot that I don’t understand about it.

The library I was porting had semi reasonable documentation outlining what classes exist and their methods and a brief description of the overall usage.  This gave me a good starting point, however the documentation didn’t include example usages and expected results, for this I was forced to delve into the code.

One development paradigm I have been interested in but have been unable to find a decent project to test it on is Test-Driven-Development and this seemed like the perfect project to try it on.  So I set to work on the first iteration getting the test set up.   Without knowing exactly what results I should be expecting I was finding it hard going, so once again I dived back into the old code.

Thankfully, the developers of the C++ library had create a fairly comprehensive set of unit tests and with my limited C++ knowledge and a text editor with RegEx Find & Replace I was quickly able to convert their unit tests into NUnit based unit tests.

For example, what started out life as:

 1: void test_row_multiply_change(void)
 2: {
 3:  row r;
 4:  RINGING_TEST( ( r *= change( 6, "X" ) ) == "214365" );
 5:  RINGING_TEST( ( r *= change( 6, "1" ) ) == "241635" );
 6:  RINGING_TEST( ( r *= change( 8, "X" ) ) == "42615387" );
 7:  RINGING_TEST( ( r *= change( 5, "3" ) ) == "24651387" );
 9:  RINGING_TEST( row( "214365" ) * change( 7, "5" ) == row( "1234675" ) );
 10: }

Quickly became:

 1: [Test]
 2: public void TestMultiplicationByChange()
 3: {
 4:  Row r = new Row();
 5:  Assert.AreEqual((Row)"214365", r *= new Change(6, "X") );
 6:  Assert.AreEqual((Row)"241635", r *= new Change(6, "1"));
 7:  Assert.AreEqual((Row)"42615387", r *= new Change(8, "X" ));
 8:  Assert.AreEqual((Row)"24651387", r *= new Change(5, "3"));
 10:  Assert.AreEqual((Row)"1234675", new Row("214365") * new Change(7, "5"));
 11: }

Now, with a full set of unit tests at my disposal I was quickly able to bash away at the library and very quickly got working code without the need to trawl through ghastly C++ code.

Hooray for Test-Driven-Development and three cheers for Test-Driven-Porting.

ps. The library I’m porting is an open source library for Bell Ringing – yes I know I’m a geek but anyone that has followed everything else in this post must also be a geek ;-).  Once I’m finished I will be releasing my code under an open source license as well, I just need to pick the right one.

pps. I may have exaggerated my hate of C++ a little.  I believe all languages have their place, even the esoteric languages like LOLCode.

kick it on

No responses yet

Nov 19 2007

Bigger Tank = More Fishes

Published by under General

Not content with having two fish tanks, I’ve just gone and order another one.  This new one is three feet by two feet by one foot and is 120 liters.  The two tanks we’ve currently got are about 75 liters in total, so once we’ve got the new tank set up we’re going to be needing some more fish to fill it.  And to think, we just got rid of our Gibbiceps Pleco which was a master at cleaning glass but was getting too big for the tank we had at the time.

This also means that we’re going to have two tanks that we no longer require.  The new tank doesn’t come with filter or heater, so I’m going to use the ones from the old tanks for now but at some point it will require newer and bigger filter & heater, which means we’ll have two complete tropical fish tanks for sale.  If anyone wants one please let me know (local delivery or collection only)!

In terms of new fish, I think one of the first we’re going to look into getting is going to be an Angelfish or two.  Our current tank would have been big enough for an Angelfish apart from the fact that we have a Siamese Fighter and they have a tendency to eat the trailing fins of the Angelfish in confined space, but with the big tank there will be lots of space.

2 responses so far

Nov 02 2007

Oops, my bad!

Published by under GrinGod [dot] Com,Site Work

I went to check my email and got greeted by some crappy spam advertising website.  Seems I managed to forget to renew my domain name registration.

Half an hour later, some desperate hunting for a back door into my hosting companies email system and I finally managed to figure out how to renew my registration (all my account details were in my imap mail account!!!).

To cut a long story short, the fact you can read this means that the registration worked and is now back online.  Maybe it’s time I shifted all my emails over to GMail and set a reminder in Google Calendar to renew the domain name next year :-)

No responses yet