Monday, 5 January 2009

Software Sloth

I know I should be babysitting, but I saw Ian's nuanced post about technical debt and thought he left one out, and it is a cardinal one.

The fundamental problem is you either do not care enough and/ or you are too proud to change your was. The blogosphere is full of good advice, there are loads of great textbooks available, and peer learning is catching on - so help is available. So why do some still not "get it" and start producing good software?

Technical debt can be excused if it is backed up my conscious, well thought through decisions. There can be justification for skimping on quality. However, I contend that most technical debt is accrued through sloth. You either do not know what quality is, because you do not care enough to go and find out. You do not know the price of short sightedness. You cannot be bothered to read good books, or participate in collaborative peer efforts to better yourself. Or you are sinister, arrogant and not interested in improving your ways, not receptive to better ideas - even when you see mounting technical debt all around you.

I am a firm believer in evolution, and if we frame the problem thus, it is clear what the real problem is: because there isn't enough talent to go around, to fill enough posts and attain critical mass, sloth is allowed to thrive. Evolutionary pressures only work when resources are scarce, and sloth is apparently a smaller problem than getting bums on seats and poor code out the door.

Or maybe I am mistaken, and quantity is the real measure of success?

Tuesday, 4 November 2008

Hello, Nagios\n

Nagios is a generic monitoring tool, and I want to use it to monitor my own application. It has a lot of built-in and offical plugins. However, it is always good to try a Hello, World-type example.

Firstly, my very interesting application. It follows the Nagios Plugin guidelines: return a value in {0, 1, 2, 3} and a status message of less than 4k to standard out. And it gives you some random sysadmin-action:

(np.c, compiles into an executable np)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char* argv[]) {
srand(time(NULL));

int r = rand() % 10;

int status = -1;
char* message = NULL;

switch(r){
case 0:
case 1:
case 2:
case 3:
status = 0;
message = "Everything is alright :-)";
break;
case 4:
case 5:
case 6:
status = 1;
message = "You have been warned.";
break;
case 7:
case 8:
status = 2;
message = "She is gonna blow!";
break;
case 9:
status = 3;
message = "Oh shit...";
break;
}

printf("%s\n", message);

return status;
}


Nagios is easy to install with this quickstart guide. You just need to configure it:

1) In $NAGIOS_HOME/etc/nagios.cfg, add a line cfg_file=$NAGIOS_HOME/etc/objects/np.cfg

2) In $NAGIOS_HOME/etc/nagios.cfg, set interval_length to a suitably low number, e.g. 5 seconds, so you can see changes quickly

3) In $NAGIOS_HOME/etc/objects/np.cfg, make it look something like this:

define hostgroup {
hostgroup_name app_hosts
alias Application Hosts
}

define host {
use generic-host
host_name app_host
alias Application Host
address localhost
hostgroups app_hosts
max_check_attempts 10
}

define service {
use local-service
host_name app_host
service_description My Application
check_command monitor_np
normal_check_interval 1
retry_check_interval 1
}

define command {
command_name monitor_np
command_line $APPLICATION_HOME/bin/np
}

The configuration is quite fidgety. Lots of required attributes, no sensible defaults. Luckily you can reuse example configuration that comes with Nagios. And there is a handy pre-flight-check feature, you just run /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg and it will give you errors and warnings against your configuration files, with line numbers.

Anyway, by now Bob is your uncle and you can restart nagios to pick up changes. Then point your browser to http://localhost/nagios and watch the action!

Monday, 3 November 2008

Any Fool Can Sysadmin

I have Windows XP on my laptop, but I needed a Linux environment for client work. The last time I played around with dual booting was in 2000 when I had just bought my self-builder home computer. I installed Windows 2000 then RedHat 6, but the whole thing failed (I suspect my then very new motherboard didn't have drivers, or something) and I had to wipe everything (using my home sysadmin skills: if anything goes wrong, wipe and reinstall!).

So, it is fair to say I am a non-sysadmin, and maybe that's why I am sometimes accused of being a girly drinker. But with VMware I am suddenly sucessful and confident - in fact I am so confident I might just run as root - it is a vm after all, what could go wrong?

I found this guide extremely helpful. VMware Player is free and easy, the guide helps to hook things up, Ubuntu is quite user friendly. Why was I so scared of sysadmining for so long?

Well, these are early days, and I might just revert to my old self if I get a problem with Linux - wipe and reinstall. But since it is a vm, that is actually a painless solution...

Actually I forget; I first tried installing Damn Small Linux using a VMware Appliance, since it was only a 50MB download. However, I didn't manage to get the network working. And my colleagues and I didn't have a clue how to fix it. So I ended up with Ubuntu. Morale of the story though, sysadmining is no fun if you can't easily wipe and reinstall.


Friday, 3 October 2008

Software Apprentice

Kerry is always talking about Dreyfus and nursing competencies.

That got me thinking: is there a book you can give to a software developer that he can follow and use to improve himself through the five levels?

Well, I haven't read it yet but Elizabeth Keogh recommended me Apprenticeship Patterns: Guidance For The Aspiring Software Craftsman. I shall put it on my list right after finishing the DDD book and several volumes on how to raise babies.

More on this topic: http://dannorth.net/2008/06/learning-to-lean - loved the Bruce Lee quote at the bottom.

Wednesday, 1 October 2008

Annoying Eclipse Configuration

I needed to get Eclipse to use a JDK instead of a JRE so I could play around with Maven.

Easy peasy? Well, no, not exactly...

"Just specify a -vm option in your eclipse.ini, and Bob is your uncle", they stated. Hah!
  • I put the option in with a blank line seperator. Doesn't work.
  • I delete the blank line after reading a blog entry. Doesn't work.
  • Hmm, it keeps defaulting to my JRE, maybe I will uninstall that so I can "debug". Que slow Windows uninstallation...
  • Now I get error messages. Maybe it is the space in Program Files? I'll put a %20 in there. Doesn't work.
  • I discover option values go onto a new line (how obscure). Combinatorials ensue. Still doesn't work.
Turns out it won't work if you don't -vm option before the -vmargs option. Why??? Worse, it will just silently die/ ignore/ not warn you. Perhaps they should work on their error messages?

But i'm not ashamed to have wasted half an hour. Others have wasted time on this stuff too.

Isn't there a standard or convention for text-based config files, and couldn't someone get Eclipse to use it?

Tuesday, 30 September 2008

Unit Testing With Threads

I saw this and started thinking back on a calculus course at university.

Wouldn't we expect a theorem like this to be true:

"for all codebases C and features F, there exists a set of refactorings R and unit test U, such that U(F) is safe under R(C)"

In other words, can we not manipulate any piece of untestable thread code into a testable one, given enough refactorings and inversion of control levers (and effort!)? Seems reasonable to me.

In a situation with 2 threads and one interaction, it is easy to imagine the combinatorial complexity of test cases. It of course explodes when the numbers go up - but perhaps we could argue that for any number of threads and interactions, we can reduce the complexity of our tests by looking at each in isolation...

If my theorem holds, you can of course turn it around and use it to knock people over their heads when they screw up thread testing - hmm, how productive that would be :-)

Interesting thought, anyway.

Thursday, 25 September 2008

Surprisingly Good Error Messages!

I was stunned recently by finding a piece of software that does something reasonably complicated, but still manages to give good error messages.

Just look at this beauty from Spring IOC:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'magiceightball' defined in file [C:\...\random\magiceightball.test.xml]: Cannot resolve reference to bean 'randomsource' while setting constructor argument; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [foo.Foo] for bean with name 'randomsource' defined in file [C:\...\random\magiceightball.test.xml]; nested exception is java.lang.ClassNotFoundException: foo.Foo at [...]

That is actually perfectly readable! Alright, I am a nerd, and I have some experience with debugging Java code, but I bet a 9-year-old child could deduce that they forgot to implement a RandomSource called Foo.

I was stunned when I saw it, perhaps because it is so rare to get useful error messages from clever frameworks. As soon as reflection enters the picture, people just give up it seems. Look at this example as a contrast:

com.google.inject.CreationException: Guice configuration errors: 1) Error at foo.BarTestModule$TestBar.(BarTest.java:18): Could not find a suitable constructor in foo.BarTestModule$TestBar. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor. 1 error[s] at com.google.inject.BinderImpl.createInjector(BinderImpl.java:277)
[blah blah]

Hmm, that's funny, I distinctly remember creating a zero-argument constructor in TestBar??? It turns out, Guice does not support injection of inner classes. And it only took me an hour to figure that out... So is this error message helpful, or rather harmful?

Hibernate is equally bad and will give you a lot of grief if you do not tread carefully. And these are popular, high-profile pieces of software, not random open-source amateur junk off of SourceForge. So how come Spring IOC got it right and these guys got it so wrong?