avatarharuki zaemon

Desperately Seeking Key Bindings

By

As you’re no doubt aware by now, I’m a Mac weenie (one of us, one of us, …) and have been for 9 months or so now having switched from Gentoo Linux - I got sick of managing my irrational need to constantly upgrade and re-compile the kernel.

When I made The Switch(tm), it took me a few weeks to re-learn the keyboard so that I could get back to using mac apps the way I had used X and before that Windoze apps. I’m also an IntelliJ weenie and the one thing I’ve found that frustrates the hell out of me is that the keybindings (for the Mac) are totally and utterly non-standard. For example, I want to use Command-W to close a tab.

I know I could go in and change the keymap myself but there are probably dozens if not hundreds of commands to map and, as I’m fundamentally lazy, I figured I’d make a plea to anyone who may have performed this heroic effort already ;-). So, if anyone out there has a comprehensive Mac OS X keymap for IntelliJ, feel free to fling it my way and in return, I’ll…um…sing your praises?

P.S. telling me to use Eclipse or be a real man and use VI key bindings aint gonna cut it either - I prefer IntelliJ flavoured kool-ade ;-)

Make Core Values Explicit

By

A developer friend of mine asked me recently what he should do when he discovers that a feature he is working on looks like it’s going to take longer than expected. Of course I recommended alerting the team lead, project manager, etc. “Well that’s fine, but then they just tell me to do it in less time and I can’t!” was his response, to which I replied “Of course you can, just take some short-cuts.” My friend retorted “but I don’t want to compromise the quality of the code!”

The problem here is that as a Developer he wants to write the best quality code he possibly can - irrespective of whether he is capable of doing so or not. His Project Director on the other hand has a deadline to meet. Unfortunately no one has made it explicit which one of these values is more important.

We all live our lives by certain values. When we do stuff, we make value judgements. We decide whether one thing is more important to us than another. Some people are aware of this others are not. Some people are acutely aware of their own values while others aren’t. For some people these values are explicit while as for others they are implicit.

Projects are no different. In fact I’d say it is critically important that the values for the project be not only explicitely enumerated but also prioritised. If this isn’t done, there exists too much opportunity for ambiguity. Ambiguity leads to conflict and conflict leads to the dark-side.

When we start any project - or restart as we have just done - one of the first things we do is to get the stakeholders in a room and prioritise the core values. Things like (honestly in no particular order):

  • Time-To-Market;
  • Within Budget;
  • Customer Satisfaction;
  • Adding Value;
  • Functioning Software;
  • Software Quality;
  • Team Satsifaction;
  • Stakeholder Satisfaction;

It can be tough to do and some people may be a little shocked by what they find out. In my experience for example, Team Satisfaction is almost always at-or-near the bottom with Software Quality hovering around the middle and Time-to-Markert and Within Budget right at the top. When developers see this they initially freak out. “What!? They don’t care about us?”

No, they do care, it’s just that if there’s a choice to be made between you staying back to meet a deadlne and you going home to <insert favourite TV show and-or-computer game here>, then guess which one wins out?

Of course priorities can change and there are no hard and fast rules but if decisions are being made that would appear to contradict the agreed priorities then alarm bells should be ringing as clearly, more communication is needed to work out why.

I dare say companies ought do the same thing. When an organisation says that it considers employee satisfaction to be the highest priority, why not make it explicit? I don’t know about you but rating employee satisfaction above say having everyone billable or customer satisfaction, is highly unlikely but hey, some organisations do tout themselves in this way. I’m sure some employees would be shocked to see the order of values that their managers have in their minds.

The fact is that it doesn’t really matter what the priorities are so much as they are made explicit. Once everyone knows, then decisions can be made and, importantly, made with the full understanding of why and how the decision was reached. The alternative leaves people assuming and expecting things based on their own set of values. Allow people to make informed decisions.

So the next time you’re asked to comprise, realise that it’s probably because the decision is not being made based on your values. Instead, find out what values are being used. If it’s on a project then put the responsibility back on to the person holding the purse strings to make that choice. It’s not a choice you should be making nor one you should even be allowed to make. Then, get over it and do your job :)

Mine's Better Than Your's

By

I’m more than a little amused at the current Rails versus Hibernate versus EJB3 versus whataver, debate that is raging at the moment. It’s not that I don’t mind a bit of argy-bargy. I think this kind of discussion is very healthy. I am a geek after all. I just find it all a little, well, tiresome sometimes. I probably wouldn’t mind so much if the arguments didn’t center around what is supposedly “best”.

Mac users would argue that OS X is better than windows, though windows sales surely outstrip OS X sales by a few orders of magnitude I’m sure. BMW drivers would argue that even the bottom of the range BMW is better than say, a top of the range Toyota, though again, I’m sure that’s not reflected in actual sales numbers. And then there is of course the oft-cited BetaMax versus VHS, IBM’s MCA versus Intel’s ISA. Motorcycles with Mick Doohan’s name on them sell for much more than those without. The guy in the motorcyle shop will thus try and convince me they’re better because they are “popular”. Just because a piece of software (or anything for that matter) is popular, doesn’t make it good. That is of course unless your definition of good is popularity.

Natural selection - and that’s how I see this - doesn’t necessarily choose the “best”, it merely chooses the fittest and, unfortunately, the fittest may well come down to things like, documentation, sales & marketing, how many other people seem to be using it and, gasp, how many books there are on the subject.

Most of the time I hear the argument for using Struts (for lack of a better example), it’s more about the fact that most people “know” struts and very little about whether it is good or not. In fact, my experience is that, while it is pretty easy to get going using Struts, it’s also very easy to shoot yourself in the foot. To the point that I’ve rarely, if ever, seen it used well. That’s not to say that it can’t be used well, just that it usually isn’t.

There are far too many factors that affect the software development process that go waaaaaaay beyond the technology and tools you use. I’ll put my nuts on the line and say that most if not all project failures have little if anything to do with the technology (except as a consequence) and are more to do with the the failings of the people, the skills and the communication.

No, what I want to see is some empirical evidence that says, hey, we built a large scale app in whatever tool it is and look it performs well, the customer is happy, our defect rates are very low, we delivered on time, on budget, and the quality of our code is excellent. And I want you to prove to me that it worked BECAUSE of the technology and not JUST because it had some really good developers on it. then, perhaps then, I’ll go recommending to a customer that they shell out a gazillion dollars to fund my latest passing interest in a tool I read about on the internet and became interested in because I was so bored with whatever tool I used on my last project.

And it’s not even that I don’t like the look of all these tools. It’s not that I’m not interested. In fact I am bored with the stuff that I write most of the time. I’ve been hangin gout for ages to find a project where someone will give me money to play with Ruby. But that’s not the problem I’m being paid to solve nor likely even the problem that I have - the two may well be different!

So rather than tell me why it’s so good, instead explain to me Why I Should Care™. (Because there are 5 books on it is not a valid answer.) Tell me how it solves a problem that I do have rather than how I can do the same things I’m already doing, differently. As far as I can tell, a lot of it comes down to personal preference and pissing competitions.

Two Tigers For Two Days In Two Minutes

By

I’ve been playing with Tiger (OS X) and Tiger (JDK 1.5) for almost 2 days now and I like it. Spotlight rocks. Dashboard widgets are neat and finally I get to do some stuff with Java 5! So here are some some observations and a few gotchas I’ve discovered so far.

First up I did an archive and install so I admit I didn’t start with a totally clean slate.

Overall OS X 10.4 seems to be a little slower and a little buggier than 10.3. Safari hangs or crashes on me every now and then and the little colour wheel is becoming an all too frequent experience. Again this may be due to the fact that I did an “upgrade” rather than a fresh install. A friend of mine did suggest that perhaps spotlights indexing was chewing a bit of CPU from time-to-time. Not sure. I’ll have to wait and see.

The RSS reader in Safari is beautiful though rather less than I had hoped for. Seriously, it would have made much more sense to build RSS support into the mail client than the web browser. There doesn’t appear to be any way to see at a glance, which feeds have new articles. The only way seems to be to “show all” in which case my news feeds totally swamp any others that I might be interested in. Maybe it’s just what I’m used to so, we’ll see how it goes.

Speaking of mail clients, Mail 2 as it’s now called has had a new face-lift and I can’t say I’m that impressed. I kinda liked the old L&F. They’ve taken away my Outbox and status bar. I had found both of these particularly useful when accidentally pressing send before I had completed an email. Again, maybe I’m just a doofus but I can’t see anyway to turn these back on. Guess I’m going to have to be more careful when I compose my emails from now on.

Spotlight (Apple+Space) is pretty damn cool even if it is probably little more than a Google Desktop but I like the fact that it’s built in, let’s me search inside files as well as through file names and it’s fast enough (for me) that I’ve stopped using Quicksilver. Spotlight categorises files that it finds; one of those categories being applications. It has integration with mail, safari, address book, etc. so it’s able to search all your emails, bookmarks, contacts, you name it. This is not to say that spotlight can really compete in any way with Quicksilver, it can’t. But I’m no power user and it was really only an application launher for me so I can probably live without it, maybe.

No matter what your feelings on the OS are, if you want to play with JDK 1.5, then you have little choice but to switch over - Apple aren’t going to ship a version for 10.3.9 or below. I downloaded and installed JDK 1.5 and followed the instructions on how to make it the default runtime for applications. This meant IntelliJ now starts up using Java 5 runtime but running java from the command-line still brings up JDK 1.4.2. The trick it seems is to play with some symbolic links in the bowels of the totally non-standard distribution that apple concocted for reasons known only to a select few I’m sure. So, to get JDK 1.5 from the command-line, I found I needed to do the following:

> cd /System/Library/Frameworks/JavaVM.framework/Versions/sudo rm CurrentJDKsudo ln -s 1.5 CurrentJDK

On that note, the latest EAP of IntelliJ seems to be a lot more stable. I’m not sure if it’s the EAP, JDK 1.5, OS X 10.4 or a combination but whatever it is, I’m grateful as I was getting sick of the weirdness with dialogs losing focus and disappearing on me all the time.

The dashboard (F12 by default) is rather like Konfabulator only it resides on a transluscent pane that appears on top of all other applications. I’ve been using the Weather, Calculator, Translator and Dictionary widgets quite a lot. Unfortunately the YellowPages widget is for US numbers only. Ooh ooh, the Flight Tracker is very cool! Not sure how often I’ll actually use it but it is pretty neat.

I also use the World Clock. Like all widgets, you can have as many open as you like on the dashboard. I currently have only three open: one each for London, Calgary and Bangalore :X. Two widgets I’d like are one for monitoring my email and another for tailing a file such as the system log. Anyone?

My next little hack is to do with the Weather widget. It seems that when creating the widget, the developers decided that evey user would of course be residing in the US; try putting in Melbourne for the city. I had no idea there was a Melbourne in Florida! But after a little sniffing around the AccuWeather website I discovered that they have a “special” syntax for describing “foreign” cities: CountryCode;StateCode;CityName which in the case of Melbourne, Victoria, Australia, translates into AU;VT;MELBOURNE. So, I thought I’d try putting that into the weather widget and bingo! I now have weather for the “real” Melbourne ;-)

I use iSync with my Motorola V3 Phone and my iPod and the new version definitely works better than the old, not to mention synchronising more of my contact details.

And that’s about it I think. Oh, the only other observation I’d make is that I do get the impression that the battery-life is a tad longer. That seems strange to me and maybe it’s just hope played out as reality but anyway, I’ll be curious to see how long that impression lasts ;-)

So, was it worth the price of admission? I’m yet to be convinced. It’s all fun geeky stuff but not much substance really when it comes down to it. Certainly most of the new features I could have had already simply by using more mature 3rd-party tools but hey, I’m a technophile so, as much as I’ll berate people for wanting to play with cool toys at work, playing with them in the privacy of your own living room is an entirely different story ;-)

Writing Readable Code

By

Sometime ago I wrote about my experiences pairing with James and the effect that listening to your code can have on the naming of variables, methods, classes, etc. Then last night, I had a very interesting discussion with Owen Rogers about, among other things, the effect that TDD has on your code.

One of the observations was that, in order to write a test (and by inference mainline code) that is understandable, you need to name your methods very carefully. The specific example that Owen gave was a factory method for creating an XmlWriter. The usually accepted convention is to name the method createXXX or newXXX as in:

public class XmlWriterFactory {public XmlWriter createWriter() {...}}

Which would then be used something like:

order.write(factory.createWriter());

The problem with this is that it doesn’t really flow particularly nicely. To illustrate, let’s re-write this last line of code into English:

order (dot) write, factory (dot) create writer

Reading the this aloud seems a little unpleasant and requires you to think a little too much about what is going on, even with such a simple line of code.

The suggested improvement was to buck the “trend” and rename some of the methods so that the code would look something like:

order.**writeTo**(factory.**xmlWriter**());

This can then be converted plain English that reads something like:

order (dot) write to , factory (dot) xml writer

Much nicer! Written this way, it’s much easier to get a feel for what is going on and for that matter to ignore the occasional syntactic noise such as “dot” (and for that matter “factory”). Interestingly however the necessary changes to the factory class make the class itself seem a litte odd:

public class XmlWriterFactory {public XmlWriter **xmlWriter**() {...}}

If you looked at the modified factory class in isolation it might not be obvious what the method xmlWriter was doing. Because there is no verb attached to the name, we have lost some of the meaning of the method when viewed on its own. And, to me, this is one major difference between a traditional design-your-classes-up-front approach, versus a more design-your-classes-as-you-need-stuff strategy.

It seems there is a trade-off between understanding a class in isolation versus understand its use in context and the nice thing about simple, readable tests, is that they give you that context as well as all the other benefits associated with good quality unit tests.

Of course this doesn’t help much if you’re building an API that needs to be used by someone else. Chances are you probably don’t distribute your unit tests and even if you did, people still feel less comfortable reading test code than mainline code or JavaDoc. Having said this, it has always been my experience that no matter how good the documentation is it’s usually almost impossible to work-out how a library should be used (especially one that is composed of many small objects) unless you have concrete examples - code presented in context.

There are obviously many other factors that affect the readability of code and naming is but one however I do find all this particularly interesting as it challenges many of the assumptions, habits and conventions that I, and plenty of others, have formed over the years.

Even more interesting to me is that some approaches favour understanding by novices while others seem to benefit more experienced developers - what seems like the simplest thing™ to one person is completely unobvious to another.

I've Finally Been Subversioned

By

Having been berated for bashing subversion based on heresay and rumour, it was about time to make the switch and actually see for myself what life without CVS was like.

As luck would have it, the guy who does all my hosting had already been considering providing SVN support so that when I asked him he was more than happy to make a guinea-pig out of me ;-)

As I didn’t do the conversion from CVS to SVN myself, I can’t comment on what is involved but I can say that it appears to have gone seamlessly and without fault. I installed the latest SVN client on my mac and was up and running within minutes.

Initial impressions are good: The command line application is very straight-foward and somehow seems more intuitive than the CVS equivalent; It certainly runs faster than CVS (or at least appears to) as it only sends diffs to the server (based on checksums); and; It will really come into its own in a week or so when I will need to perform a bulk rename of files for the book - the real reason I needed SVN in the first place.

The only mildly dissapointing thing is the rather less than wonderful support in IntelliJ: Even in the latest EAP versions it seems to be much slower than the command line application and doesn’t have an option for hiding the .svn directories. No doubt all of these will be “fixed” soon…right?

The best part for me is the repository versioning: every commit increases the repository version number so in effect you get a new tag with every commit. This will come in particularly handy for some code analysis tools I’ve been developing that track metrics over time. Previously I had to go through hoops to try and work out what changed and when in CVS. Now SVN gives me this information for free!

So all in all it’s happy sailing on the SVN ship. That is of course until my repository becomes corrupted. JUST KIDDING!

I Suppose I should Be Flattered

By

I was doing a little reading on different types of rule engines today and stumbled upon this article. As I was reading through it, I had an eerie sense of dejavou; I was sure I had read this somewhere before. In fact, it almost sounded like something I might have written.

A quick search through my blog and there it was, an entry posted in September 2004.

The thing that amuses me most about copying someone elses stuff word-for-word is that you inevitably end up copying all their (or in this case my) mistakes as well. So whilst I’m flattered that someone with obviously unquestionable integrity would even consider re-using my thoughts (and even spruce them up a bit in the process) I would have thought that bloggers, armed with trackbacks and hrefs, and indeed developers in particular, would have left copy-and-paste re-use behind.

When is a String not a String?

By

So I’ve been stumbling along writing this book and today I wrote some code where, rather than using good old Strings, I instead chose to use CharSequences. Why?

Well for one thing, I wanted to be able to process both Strings and StringBuffers alike and, thanks to JDK 1.4 and JSR-51, that’s possible as they both implement CharSequence- very nifty indeed. More importantly though, I wanted to be able to process data from files as well as in-memory.

Now, admittedly I could have written my code to process Readers or InputStreams instead and used a StringReader, etc. But really, when it came down to it, the algorithm I was writing suited strings and characters not bytes and buffers and all that hoo-ha and I wanted to keep it that way.

So, I thought to myself, I would do the opposite. I would write a CharSequence that wrapped a Reader. That shouldn’t be too difficult now should it? But then another thought occured to me. Before I leap into writing a whole bunch of code that I’d need to test and gasp maintain, maybe someone else had already done the hard work for me; maybe even the JDK!?

A quick flick of the wrist and IntelliJ brought up a class heirarchy for me and what do you know? along with String and StringBuffer was the little used CharBuffer from the NIO package. Another little present courtesy of the JSR-51 group.

A CharBuffer facilitates, among other things, memory mapped I/O, meaning you can address a file on disk as if it were a contiguous array of characters in memory. And, because it conveniently implements CharSequence, can be passed into my code just as any of the purely in-memory implementations.

The other thing I like about CharSequence is that it’s an interface. This makes it possible to decorate them and gather performance statistics really easily. Yes, yes, all you AOP weenies sit down and stop waving your arms about. I know your new (ok not so new anymore) fandangled whizzbang toy can do that too. But I don’t have to learn a new language or tools to do it. One day perhaps but not this one in particular. Believe me, my paradigm has been shifted quite enough and I’m giving it a rest for a while ;-)

The only thing missing is that, surprisingly, the Character class doesn’t implement CharSequence. I’m not sure how useful that really would be but I like the idea if only for completeness sake. It certainly wouldn’t be hard.

Anyway, I think I’ll be looking for opportunities to use my new best friend where I would usually have used a String. The only caveat is that a String is guaranteed to be immutable while a CharSequence isn’t. Oh and you can’t be guaranteed that equals will work between them either. No matter, I can still see the glint of those shiny golden nails from here :)

The hidden chambers that nobody can understand

By

Not usually one to rip off someone else’s quote, I couldn’t resist this one. It’s possibly the best description of corporate software development I’ve seen:

If you look at software today, through the lens of the history of engineering, it’s certainly engineering of a sorts but it’s the kind of engineering that people without the concept of the arch did. Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. – Alan Kay, creator of Smalltalk

If you’re interested you can read his other views on software development and languages.

It's Like Being Back At Work Only I Don't Get Paid

By

I’ve taken 6 months off from regular, full-time, consulting work. After nearly 16 years divided between software development and martial arts training and teaching I needed a break. I’d never really had a real break; If I wasn’t working, I was in Japan training. That, coupled with my ever growing disenchantment with what can only be described as glorified body shopping, prompted me to take a 6 month break.

It has been fantastic for many reasons. Suffice to say, I’ve been enjoying at least a glimpse of how it might feel to one day be independently wealthy. Alas, I fear that day may never come but, fingers crossed, never underestimate the power of positive thinking! Now where did I put that lotto ticket… ;-)

The timing was perfect; no work; lots of free time; and as fortune (or have I spoken too soon) would have it, an opportunity, along with a contract, to write a book landed in my lap. Nothing particularly rivetting mind you; Nothing earth-shattering nor ground-breaking. In fact a topic that has, in most peoples estimation, been done to death. But, if the publisher thinks there’s a market, then who am I to knock back the chance to show how inept I am with the English language, not to mention demonstrate to the world how truly woeful my coding skills have become. Besides, it’s a topic I personally find interesting.

And so it came to pass that, after nearly two months in the wilderness, I finally found something to rant about!

For a start, having a publisher and editor and all the hooha that goes along with producing a manuscript, is really no different than having a customer that wants a bit of software written. They have deadlines. They want upfront estimates and plans. They think that somehow, magically, I’ll know at day one what the entire book will look like down to 5 levels of headings! And worse, when you send them a sample chapter, they write back saying, “thanks for that but not only is it not complete, it could do with some pictures, and go into a bit more detail.” Riiiiiight. That’s like asking a user for feedback and recieving “um, it doesn’t work”. They don’t seem to understand that I don’t write Mills and Boon for a living. I’m a geek. I write, well, geeky stuff. Like code and scripts and, well more code.

Don’t get me wrong, I do enjoy writing. Actually I think I enjoy hearing the sound of my own voice more than writing but that’s another matter. What I’m not keen on is writing for 10 days, submitting it, and finding out that “um, actually, no. Sorry. That’s completely wrong. Please start again.”

The publishing industry seems to run waterfall. I was absolutely astonished. It had never even occurred to me that would be the case. They expect you to have a finished chapter submitted pretty much in it’s final form. First time. Every time. The idea of submitting a half-baked chapter for a sanity check seemed almost abhorrent to them. “Dear god!” I thought. “What is an editor for?” Not what I had originally assumed, obviously.

I need constant feedback. I need to know if I’m heading off into the rapids, not once I’ve capsized, but at least a few days before if possible. I also want to work on different chapters at once. I’m more than happy to add a bit here, a bit there, move stuff around. That’s just the way my brain works. I like to put together little pieces of the puzzle, bit by bit. I like to layer on the different aspects of the work; tests; code; explanation; bit of introduction; etc. It’s the same approach I take to writing code. I guess that’s just how my brain works.

So, after a bit of back-and-forth with my editor, we finally got it all straightened out. She was most understanding and very helpful. She explained what she needed and why. She expanded a little on the areas she thought needed more explanation, figures, etc. And once again I was happy with the content. Nevertheless the process remained waterfall and this continued to bother me.

After a little brainstorming with my saviour in all things planning, James, the antedote became clear. I just needed to do what any self-respecting agile bigot does in a waterful infested pool; erect a facade; interpose another layer between myself and the editor; make it appear that there is a perfect, uninterrupted, cascading of chapters from top to bottom. We decided that it would be a good idea to use my work colleages and a couple of my siblings (both geek types) to review and comment on what I was doing as I went. They would understand I hoped. They knew what it was like. Then when we were happy with the content and layout, I’d send the completed chapters through.

So here I am at the beginning of the last 28 days of the first 25% of my first book, changing tack mid-stream and paddling like crazy in the vain hope that I won’t fall over the edge of a literary Niagra Falls.

God Speed!

South Africa

By

I’m back, for all that is worth, from 2 amazing weeks in South Africa. It is a truly amazing place. I have travelled a lot over the years but S.A. just blew me away. Words simply cannot adequately describe the beauty and splendour of the country.

The people are a little like Australians or possibly even New Zealanders in temperement and sense of humour. They are incredibly kind. The difference being the racial makeup. The large african population makes the place just amazing. The people are so happy in what can often be dire circumstances. Especially in the shanty towns (or “townships” as they are known) where literally millions of displaced people “live”.

Thankfully for most of the time at least, there was hardly a hint of racism. Unfortunately it does still exist especially the further out from a major city you get. When I did encounter it I was nearly brought to tears, followed by rage and then a sense of helplessness as I realised there was nothing I could do. It goes both ways and whatever justification or pseudo-scientific mumbo jumbo either side can concoct, when it comes down to it is 100% cultural bias, ingrained from birth and for which the only cure is time.

I started to pick up a little Afrikaans. “Who undid my bra?” is a pretty close approximation for the pronunciation of “How are you?”. Well at least now you’ll remember it :). I even started to sound like a local. It’s a great language with an unfortunate heritage. I would still like to learn more.

The food is just incredible and a downright steal for anyone with foreign currency - I don’t think we had one bad meal anywhere. Boerwors (long beef sausages), ostrich steaks, biltong (dried meat like jerky), bobootie (like shepherds pie), you name it.

The wines are pretty good, especially the whites and cabs. Can’t say I enjoyed the local Merlot or Shiraz much. Whatever your tastes it’s certainly worth checking out the wineries of Stellenbosch, etc.

I spent most of my time in Cape Town which is in itself an amazing place to visit. You could spend a year there and still not get through all the things to do - most of which are free or as close to free as you can get. The weather, in Cape Town at least, is a lot like Perth. In fact The Waterfront can be compared to Fremantle only a lot bigger. The further north you go the more humid it becomes but I seemed to aclimatise pretty quickly. Lucky really as no one seems to have heard of fans, let alone air-conditioning :-)

We hired a car which for us was the ideal way to get around. It just gave us the freedom to do whatever we wanted, when we wanted. So some tips for the roads:

  • Speeding is the norm and fines do apply however they are rarely followed up on. We met people who had outstanding fines from 10 years ago;
  • Drink driving is not tolerated and will likely land you in jail;
  • Watch out for mini-bus taxis as they are generally over-filled, are rarely road worthy and seem to have a total disregard for anyone else on the road;
  • Watch out for expensive mercedes benz as they are usually doing about twice the legal limit and have a total disregard for anyone else on the road;
  • It is normal to move over to let other cars pass you which happens all too often on blind corners, hills and over solid white lines and sometimes in both directions at once!;
  • If you overtake someone it is customary to flash your hazard lights a couple of times to say “thank-you”;
  • If you are overtaken and someone flashes their hazard lights, it is customary to flash your headlights one or twice in acklowledgement;
  • And finally, the annual road toll for South Africa is…a staggering 10,000!

Just some of the things I saw and did:

  • Hiked up Table Mountain starting at Kirstenbosh. Takes anywhere between 2-8 hours depending on your level of fitness and the route you take. Be careful of the “Table Cloth” that rolls in to engulf the entire mountain top. If high winds are predicted, you can pretty much forget climbing it as you won’t be able to see a thing;
  • Took the cable car up Table Mountain;
  • Lions Head sits beside Table Mountain and is a gentle 45 minute walk;
  • Kirstenbosh is quite an amazing botanic gardens at the foot of Table Mountain. It’s the biggest gardens I think I’ve ever seen and home to some of the most amazing Proteas. It has to be seen to be believed;
  • The Waterfront as I mentioned earlier. Shops, cafes, bars, more shops, boat rides, restauarants, German beer gardens at which MANY MANY pints of “anniversary ale” were consumed;
  • Mountain biked around the Cape Of Good Hope, Cape Point, etc. through amazing national parks. Rode past snakes, turtles, lizards, and baboons all within metres of us;
  • The wineries of course!;
  • The open top double decker bus tour of Cape Town;
  • Green Point market where you’ll find just about every kind of hand-made souvenier or gift you could ever hope for;
  • Camps Bay where all the youngsters hang out on the beach. Mind the water though as the temperature sits somewhere between 11C and 13C;
  • The wineries of course!;
  • Visited a private game reserve. Name an animal and I saw it, up close. Our guide, and UNIMOG driver, Nadia was cause for a mild case of khaki fever ;-)
  • Rode an African Elephant;
  • Swam in a lagoon in the middle of nowhere. It reminded me of something out of Tarzan :).

And that was day one! Just kidding but seriously there is so much to do. I didn’t get to do anywhere near as much as I would have liked. Some of the things I want to do next time I visit include:

  • Rock climb Table Mountain;
  • Visit Robben Island where Nelson Mandela was impresoned;
  • Hike some more mountains - there are too many to name!;
  • Mountain bike through Kruger national park;
  • Visit Pretoria and Sun City;

To top it all off, I was caught in a natural disaster. The small town I was staying in, Heidelberg, about 4 hours out of Cape Town, suffered the worst flooding ever recorded - 189mm of rain in 24hours. The rivers swelled and took out bridges and roads. Farms were flooded and crops destroyed. I saw cattle drown and two storey buildings submerged. Phones and electricty cut-off. Amazingly none of it managed to fall into the dams currently sitting at 15% capacity at the start of what is usually the driest season of the year. And all in front of my eyes. If you’ve ever seen a flood on TV, it really doesn’t do justice to the awesome power of Mother Nature at her worst.

If you’re thinking of visiting Cape Town, make sure you call Sally de Jager. We found her details on the ’net and from there organised a guided mountain bike tour of The Cape. She is a magnificent guide and a wondeful person. She is very knowledgeable and will literally organise whatever tour at whatever price you can afford. For us she organised a hike, followed by biking around the cape then it was off to sit on one of the many beaches to drink wine and watch the sun go down. Oh and her boyfriend is an Australian so she understands us :-).

As I mentioned at the start, it would take me a month to describe all that I expereinced in 2 weeks. Certainly a life changing trip. So if you’ve ever even contemplated a visit, do it!

JRules Memory Leak Gotcha

By

About 6 months ago we were profiling our application to ensure we had no memory leaks, etc. We did find some and we were able to fix them pretty much immediately. However, today I happened to be chatting with a colleague who is investigating a memory leak in another application and it sounded scarily similar. So in the interests of all you JRules developers, here’s a little gotcha.

JRules maintains a binary, 1-to-many, association between the rule set (IlrRuleSet) and the, possibly, many instances of the working memory (IlrContext) - Also referred to as a “rule engine” by the JRules documentation. I’ll spare you my diatribe on binary associations for now, suffice to say that if you weren’t aware of this little “feature” (or if you were and simply hadn’t given it much thought) you’re in for a nasty surprise.

When you’re done with an IlrContext the natural thing to do would be to simply remove all application references to it and let it be garbage collected. Unfortunately, due to the two-way nature of the relationship, this doesn’t have the expected effect. Instead, because the rule set still holds a reference to the context, it will NEVER be garbage collected.

To combat this problem, ILOG thankfully provided a somewhat innocuous looking method IlrContext.end(). To quote from the documentation:

Prepares this rule engine instance for garbage collection. After this call, the engine will not keep any reference to this rule engine instance. The rule engine instance will be detached from the ruleset and will no longer be notified of modifications on the rules. The rule engine instance will also disconnect all its tools and all the related resources will be released. If the application does not keep this object, it is then subject to garbage collection.

In other words, anytime you’ve finished with a context and wish it to become a candidate for garbage collection, be sure to call end() or be prepared for a slow and painful application death as the heap runs out.

One final tip, if you make use of context pooling, be sure to also call IlrContext.reset() before returning it to the pool. This will remove all references to your application objects within the context.

<blatant-plug>If you’re in the market for a cheaper alternative, you might like to try out the latest version of Drools.</blatant-plug>

P.S. If anyone from ILOG is listening, this is exactly the kind of problem WeakReferences (and WeakHashMaps in particular) are designed to prevent :)

Assistant Orange Peelers

By

My father is a commercial airline pilot. He’s been flying since around the time I was born, 32 or so years now. He’s flown everything from light aircraft through 707’s, 767’s right up to the latest 747-400 - the ones with the winglets and beds for the 2 crews, enabling them to fly non-stop Sydney to London.

Pilots must undergo medical and practical examinations each year in order to maintain their rating on a specific aircraft and apart from actually flying, he has at various times been a training captain working out of Boeings Washington base. From there he teaches and re-trains pilots on simulators to either attain accrediation on an aircraft they haven’t flown before, or simply to renew their existing accreditation. Obviously he has lots of stories to tell but by far and away the most interesting group of pilots he’s ever had to train were Russian commercial airline pilots.

Back in the bad old cold-war days, defections to The West were common place and of great concern to Russian authorities, especially when it came to pilots. You can imagine that it wouldn’t take much for a commercial airliner to continue on to Japan or parts of Northern Europe. So, no doubt in an effort to counter this, and also possibly to give as many people as possible a job, Russian commercial airliners would sometimes have as many as 6 crew members in the cockpit with each one assigned and trained for a specific task. My father used to joke that they would have a Navigator; Radio Operator; Flight Engineer; Pilot; Co-Pilot; Orange Peeler; and an Assistant Orange Peeler. Re-training them on aircraft that require at most a 2-man crew was challenging to say the least.

This kind of “siloing” occurrs all too often in IT shops as well where each person has a specific task: The GUI Guy; Miss Middleware; Database Dude; Build Master; Application Deployer. Not such a bad thing at first glance I suppose - it’s always good to have someone in the team who knows about these things. For example, if you ever need to know something about how the Object-Relational-Mapping works, go see Billy Bob.

Another argument put forward is that by concentrating responsibility and accountability it removes the “burden” from the rest of the team. In practice though, this approach seems to lead inexorably to demarkation disputes further resulting in much finger-pointing and scape-goating. Cries of “Can you fix that, it’s in your code” or “Who’s been making changes to Blah.jsp without asking me?” can often be heard. What’s worse is how this can materially affect the productivity of the whole team - “She’s not in today so we’ll have to wait until tomorrow to make those changes” or “You’ll have to wait until the Build Master gets back from lunch before we can do another drop for you.”

It seems odd that a modern software developer cannot or is unwilling to become multi-skilled. The days of being solely a JSP guru or COM expert are gone and have been replaced with collective code ownership and the idea that moving people around is a good thing.

Or perhaps it is management worried about losing control? Perhaps a team who’s members have become self-reliant may decide that they can make it on their own and “defect”?

Using Lucene To Find A Date

By

For the next 3 weeks (and for the past few), I’m the DefectController. I get to watch the defects roll in, assess them, and hand them out to the approriate developer (which may be me). Last week I saw a rather odd defect pass by:

org.apache.lucene.queryParser.ParseException: Too many boolean clauses when performing date range search.

My first reaction was puzzlement replaced shortly thereafter with shock as I thought through the problem. It occured to me that the most obvious cause would be the unthinkable: the developer must have enumerated every possible date in the range and included them ALL in one gigantic OR condition.

A bit of groking later and shock turned to horror. Fortunately, the developer had not done as I suspected. They had done the correct thing and generated the correct Lucene criteria in the form:

dateOfBirth:[19700801 TO 20030615]

Unfortunately, that left only one option: It must be Lucene!

Two minutes on Google and the BuildController turned up, among others, this link. Yes indeed, it seems, Lucene does enumerate ALL possible dates. In fact depending on the granularity, it will end up enumerating all possible seconds! Apparently this is not a bug nor even a feature but a “known behaviour”.

So now here’s the thing that puzzles me. It would appear, from the documentation, that string ranges are also supported allowing us to find say, people where:

name:[Albert TO Betty]

This being the case, does Lucene enumerate ALL possible names? I find that hard to fathom. If it does, then I give up now. If not, then couldn’t we just encode the dates as umambiguous, comparable strings? something like:

dateOfBirth:[19700801 TO 20030615]

Look familiar? It should. I just copied and pasted the original example. But if this time around we consider the dates as strings of the form yyyyMMdd instead of attributing any special notion of date, wouldn’t that solve the problem? Wouldn’t that also easily allow us to perform partial range searches that include say only the year or year and month?

A Lucene expert I am not but all the links we found suggesting various other “work-arounds” (one of which suggested upping the limit on the number of clauses!) seemed little more than hacks. So, please, please, please tell me I’ve missed something obvious because the solution really does seem that simple to my feeble bwain.

Where's The Problem?

By

One of the biggest problems I see over and over again is the difficulty support and maintenance teams have diagnosing problems. It’s unfortunate but developers have a knack of writing code for Happy Days scenarios - when the software works, it works well; when it fails, it can be a disaster.

A cow-orker and I were recently discussing the use of assertions in production code. He had previously been discussing the topic with one of his colleagues who had suggested that their existence was a smell; that it indicated a lack of testing.

Now, enough has been said on the topic of unit testing so suffice it to say that the great thing about unit testing is that it’s easy to ensure your components work as advertised. You can even, and in many cases should, test what the behaviour would be given invalid input such as NULLs, etc. Then of course we move into integration, functional, acceptance, regression, etc. testing to prove that the application hangs together as a whole.

The problem is that tests don’t necessarily prove that the software does what it’s supposed to GASP!. Rather, tests prove that software works for the given scenarios and the assumptions made and the plain fact is that these do not always match reality. We may have the greatest, most comprehensive test suite in the known universe, but if it’s testing the wrong things, it matters little. Sure, in a system over which you have complete control, high levels of functional/integration test coverage can compensate but even then, even 100% code coverage doesn’t equate to 100% accuracy. In particular, at best, it is difficult to test for and therefore prevent clients of your code from passing invalid parameters. In fact if you’ve ever written and published a public API you’ll know that, by definition, it’s impossible.

The further into a system a problem propogates, the more difficult it becomes to diagnose and the greater the likelyhood of “damage”. One of the major benefits of production code (as opposed to test code) assertions is that at run-time we can detect and prevent unexpected scenarios as early as possible, thereby preventing them from propogating. Maintenance developers and those familiar with the Fail Fast axiom will appreciate how important this is in a production environment.

Environmentally-Friendly Configuration

By

Dave came over to me the other day and said he wanted a new build check written that searches the entire source base for "C:". It’s a familiar problem where supposedly automated scripts refer to specific directories, paths, etc. Move the script, run it in another environment, and BLAMMO!

I recall some colleagues telling me of a problem they had once where the system had been running fine for months in development and then one day it mysteriously started failing, everytime, on every developers machine. It turned out that ALL developer machines had been configured to communicate with the message queue on another developers machine because that’s what had been checked in to CVS.

More recently, we encountered a problem where the UAT environment worked but not System Test. Again, it turned out that the default configuration for a remote URL was, lo and behold, set for use in a UAT environment. Each time the System Test deployment was run, it was communicating with the wrong server. No one noticed it at first because, aside from the server name, the string of request params is the same in all cases.

These days, as a bare minimum, we strive to have ALL “default” configuration values set to something along the lines of "THIS_IS_WHERE_THE_VALUE_OF_X_NEEDS_TO_GO". This way it sticks out like the proverbial Dogs Bits when you’ve forgotten to tailor something for a specific environment.

Then we use build properties such as configuration=development, configuration=uat, etc. specified on the command-line that allow the build scripts to substitute in all the various values appropriate for the intended target environment. This, coupled with some Build Watermarking, almost guarantees that this class of configuration problem is a thing of the past.

That is of course until one of the developers comes to you and proudly explains that they have “discovered the problem. There were these strange values in the reference data scripts, so I changed them all to sensible defaults and checked it in.”

Unit Tests As Complexity Sponge

By

A number of people have variously commented that unit tests may in fact be more about design than actual testing. Many others (the links elude me at present) have also complained about the undue burdon imposed by a large number of unit tests and that because of this, and other very sound reasons, they prefer acceptance tests. If I was ever in any doubt about the importance of acceptance tests, I was certainly convinced after the last project where acceptance tests would fail where no unit test had, due no doubt in large part to the fact that the acceptance tests also acted as integration tests.

One thing I did notice however was that over and above their usefuleness as a design tool, unit tests seemed to act as yet another positive constraint helping reduce the overall complexity of the code. Because developers were forced to write unit tests, they were forced to produce relatively simple, testable code. Much simpler, I believe, than would have been the case otherwise. The down side to this testability was that in many cases, the corresponding unit tests were rather more complex than we would have liked. And, as noted previously, complex tests tend to be brittle and this has a knock on effect with respect to maintenance. But does this really matter?

Ultimately what is important is working software (for which you have acceptance tests) and clean, easy to understand code that is hopefully cheaper to maintain. You could choose to throw away all those “dirty” unit tests once you reach production and rely solely on your acceptance tests; or you might choose to buy new ones through refactoring/re-writing; or you may decide that the unit tests are worth the extra effort to maintain.

Whatever the course of action, it seems to me that, yet again, unit tests have benefits beyond simply (or not as the case may be) producing “correct” code.

Something Tells Me This Could Be Bad

By

ADGU3163I: Suppressing console message display from server because the arrival rate of 38.76per second exceeds the threshhold rate of 10

CVS Saves My Life Once Again

By

Some time ago I trashed my linux machine by running rm -rf on a logical mount that, for reasons too mundane to discuss, was pointed at the root partition. Yes yes, snigger snigger hehe but tell me you’ve never done something similar :P. Anyway, a day or three later, I had resurrected my machine and restored all my files from those non-existant backups that we all vow to make…one day.

I deploy stuff to my various websites using ant scripts. Each time I deploy a new version of a product or project or even just make a change to some static HTML, it’s automatically shipped using JSCH then some shell commands are rune using SSH to move stuff around/configure things as necessary.

Up until about an hour ago, I had been using a semi-colon (;) as the command delimeter with no issues at all. There is problem with this that I had never considered - If any of the commands fails, the shell keeps on executing the remaining commands! Now in my case, one of those commands changes directories and is followed immedately by, you guessed it, `rm -rf *code. Not a problem if everything goes to plan but I had just recently renamed said directory! Needless to say, it wasn’t pretty.

It then occurred to me that what I should have been using were double-ampersands (&amp;&amp;) which terminate execution at the first failure. Even better would be to simply rename (move) the existing directory and create a new one; My newly adopted strategy.

Thankfully, all my projects and web sites are in CVS so restoring them is never a problem which got me thinking about all the bits of code I’ve seen commented out or the unused classes left lying around because, like all those off-cuts of building material you’re keeping in the shed, “who knows when I might need that.”

More often than not CVS is used purely as a central repository that all developers can access but it can and should be more than that. Having everything in CVS allows greater fluidity in development. It allows developers to try something out and if it ends up completely borked, well, we can always just roll back. James even suggested (now that he’s a CVS guru along with Jon :P) using CVS branching to do some speculative changes without disturbing the guys on the trunk whilst still allowing us to check-in the code. This is certainly something I would have been extremely reluctant to do even 3 months ago but having seen it work out (so far) for one of the projects on which we depend, I’m rather more inclined to give it a go.

As developers, we need to feel comfortable with and trust that all of this is possible. I doubt that many people I’ve met actually understand all the subtleties and features of CVS, myself included. One thing I know for sure is that resurrecting dead files in CVS isn’t nearly as simple as it sounds. I’m hoping Subversion will address this but right now, something tells me that after everything I’ve just said, using beta-software for SCM on my critical projects is, perhaps, not the smartest thing one could do.

McAppy Time

By

Something appeals to me about the way Mac OS X applications are distributed. Sometimes there is an installer (boo!) but more often than not there is only one “file” to drag into /Applications. I say “file” because although it looks like a single file, it’s actually an entire directory structure with a special folder Contents containing meta-info that the Mac OS X GUI understands. Sort of like an unpacked Jar file but for native applications. Best of all, if I decide to remove the application (I’ve played with about 10 IM clients so far) just delete the application and whoosh, it’s gone. In most cases about the only thing left lying around are preferences in ~/Library/Preferences.

So, finally understanding all that, I thought I’d try my hand at building a deployable application - called a bundle. I found a web site that documented most of the steps required. I also found an Ant target that allows you to generate a bundle from a build. The next step was to build an application.

Being the Java Snob that I apparently am, I naturally decided to try deploying a Swing app. The fact that Mac OS X comes with Java out-of-othe-box is pretty cool. What’s more the deployment mechanism supports Java apps directly meaning that besides some minor L&F issues here and there, Java applications slide right in amongst native applications.

So, I thought I’d put a “Launcher” GUI on Simian just for fun. Nothing special. Certainly nothing to replace the IDE plugins others have written for. And here’s a picture. Makes me want to work on a Swing project even more. Though I believe JavaScript is all the rage now ;-)

One thing I didn’t do was specify an application icon but that’s as simple as converting an image and dropping it into the Resource folder inside the bundle, something that can be achieved by using the icon parameter on the ant task.

The other thing I need to do is to find an ant task that can create disk images - the standard way Mac applications seem to be distributed.

And finally, just as I was about to post this, I stumbled across a three-part series on making your swing applications play nicely on the Mac.

Not sure if any of this is any better, worse or really just the same as a Jar file. But it’s kinda fun in that geeky kinda way.