23 June 2008

The End is Nigh - but wait, I haven't checked in my code yet!

I set my alarm, get up at 7:30 or so, walk my son to school (he has a future, you know), and hop on the bus. On the bus to work I practice lisp, because it's the language of the future, you know. At the office, I write more software, helping replace legacy systems with future-oriented web technologies. Helping the bank acquire more future wealth. Gathering the crumbs for my own future wealth. I think about my future projects, what kind of a startup should I build, what kind of wealth I will accumulate, and what will I do with it. Where will I live, who will I know, what will I be doing in and with the world? And my children? What kind of a world are we building for them?

And then I remember: there is no future.

When the rain passes, moving up the coast, we cross the creek on the pontoon, pulling ourselves across the slow flow on a simple, effective contraption of empty oil drums and steel grating, and walk to the beach. Sand after rain seems like hope or the promise of forgiveness—, a reminder that after we've gone, when the last human passes, the world will continue, and will begin to erase the signs of our time on Earth. Like the maze of footprints on the beach and the excavations and constructions of small children with plastic spades and buckets, the traces of our activities will be erased by weather and time and non-human lives.

When and how this will happen, I don't know. I do suspect it will happen not catastrophically and globally but gradually and patchily. Human existence, already grim in much of the world, will become grimmer, then desperate, and the expansion of regions where humans cannot live will accelerate. There, in those deserted and ruined places, the record of human life will begin to fade.

(from pohanginapete, with thanks to Dave Pollard for the link)

22 June 2008

Drive massive amounts of traffic to your blog

Oh, I'm talking about traffic again. Didn't mean to, honest ...

A while back, Dhaval blogged about Google Analytics. I had installed this snippet of javascript on this blog at the beginning of this year and it's better than television. OMG I got two hits yesterday I have *so* made it!!!1! It's the first thing I check in the evening when I get home. Ok, the second thing, after reddit. And the arc forum.

Anyway, I digress. As Dhaval mentions, it's full of charts and analyses and breakdowns. But a powerful little feature that deserves a bit of attention is the "keywords" report. It tells me, for all hits that came from searches, what terms were used in those searches. So even though "conan dalton" is the single dominant search expression, there are many more search expressions containing "onmouseout", "oracledatasource", "hibernate". Because I happened to write short articles describing my experience with problems in those topics.

But I don't think they're my most interesting articles! I'm a human being, I have thoughts, feelings, emotions, I care about things like crossing the road, and what my children can teach me about business. onmouseout isn't really that important, in the grand scheme of things!

Anger and denial over. So, analytics teaches me what drives people to my blog. It looks like I should stop writing about me, and write some more about the behaviour of onmouseout when using Spring to configure Rails with Markaby and ActiveHibernateRecord buzzword buzzword Oracle DSL .NET iPhone buzzword ...

But can I go further? Yes! It turns out that Google have another great little tool, Google Trends. (Yes, I'm expecting a nice cheque from them one of these days). Hot Trends tell me what people are interested in today. Armed with this knowledge, all I need to do is blog about today's top ten search expressions and voilà, Blogger will collapse under the strain. So, here goes:

  1. thomas finchum - never heard of this dude. He's a diver. Some pictures.
  2. david boudia - another diver. What's going on? Is it the olympics or something? Why did nobody tell me?
  3. gwen araujo - transgender woman beaten and murdered. I remembered Boy's don't cry. It made me cry.
  4. radio days - a Woody Allen film. From 1987.
  5. henry klum - Heidi Klum's son. He went to the park.
  6. emphysema - a lung disease. Caught by Amy Winehouse. She's a singer. Ouch.
  7. michelle brown - her identity was stolen
  8. crisco.com/grilling - Seriously? Google, have you checked your trends algorithm?
  9. ironman coeur d alene - a Ford-organised triathlon. This year, with less waste, apparently. Great.
  10. ocean breeze - well, who doesn't want more of that? But ... Top 10?

I'll let you know what happens to my stats. In the meantime, I've learnt some stuff today that otherwise ... otherwise ... I might never have learnt. Thanks, Google!

13 June 2008

No, no, and no!

Living in France, I didn't vote in yesterday's referendum on the Lisbon treaty, but I'm pretty sure I would have voted against. Unlike some in office, I might have even made the effort to read a summary of what we were asked to vote for. There was a time when I believed in greater European integration for economic self-defense against the established and upcoming economic giants of the world - 300 million people have a lot to say, but if you took the entire population of Ireland and plopped them in India, I'm not sure anyone would notice.

More recently however I've become skeptical of centralised power and big bureaucracies. A big government is just as likely to screw its own people as defend against foreign interests.

It's kind of sickening to see other European politicians slamming the Irish people for their decision, regardless of how poorly the decision might have been made. Those politicians know where Lisbon would be if their own peoples had a say in the matter. "21% of Irish people decide the fate of 300 million Europeans" - WTF? Is it preferable that a few dozen politicians make this decision? Do you, like, *trust* your leaders??

Back in the Dark Ages, legend has it, Ireland "saved civilisation" by taking the scholarly works of the Holy Roman Empire with them as they fled to the safety and isolation of this little island far from the wanton destruction of heathen invaders from the North. It's kind of funny to think this country, with its silly insular, provincial political factions, might now be the last outpost of democracy in Europe.

On a completely unrelated note, and I hope you'll forgive me for being irrelevant, reddit kindly pointed out this video (52 mins) of an academic demolition of standard WTC collapse theories. It says much the same as 911 Mysteries, but without all the drama and excitement. Just a simple analysis of publicly available knowledge - photos, videos, and witness accounts.

23 May 2008

Programming for the Stone Age

Warning: Rant Ahead. I just need to get this out of my system. You don't have to read it. It might look like I'm beating a dead horse, but recently I found this particular horse alive and kicking.

We have to do it this way because otherwise it will be a maintenance nightmare

So, here are some ways to make your code maintainable:

How to Write Maintainable Code

  1. Write helpful, detailed comments
  2. Always code to interfaces: you never know when we will need to substitute a different implementation
  3. Your Controllers delegate to Façades, your Façades to Services, and your Services to DAOs: this allows us create modular and re-usable components for greater flexibility
  4. Extract a maximum of configuration information to properties or xml configuration files. That way, the future maintainers will be able to modify the program's behaviour without even needing to recompile!
  5. Actually, if you can put some if this information in the database, even better, you can tweak the application while it is running!

Oops! Sorry, actually, I meant to publish that in a different universe. Here's the corrected version.

How to Write Maintainable Code

  1. The code is the documentation. Comments get in the way and are often wrong
  2. A smaller codebase requires less effort to understand it, hence will be more easily assimilated by future maintainers. This means don't create interfaces until you actually have varying implementations
  3. The simplest possible code is also the hardest to break accidentally, and also the easiest to introduce new features to. Don't add layers until the need for them is manifest
  4. Extract only the minimum possible configuration information. If later you find something needs to be configurable, extract it then. Each configurable item is another piece of indirection, adding size and complexity to the system.
  5. If something needs to be configurable, put it in the database only as a last resort, and only if there is a proven requirement from real users that this needs to be configured, and then only if they are willing to pay not only for the initial development cost of this configurability but for the future maintenance costs arising from the much-increased size and complexity of the system as already described.

Two worlds, opposite extremes, both seeking the same outcome: to protect future maintainability. The other-universe of the first approach isn't a weird quantum thing, it was just twenty years ago.

Comments

There was, indeed, a time when languages imposed a (small) upper limit on the length of names. So you had this

sndClsAppMl(char* addr, char** tmpl, int cntyCd, int clsCd)

And now you have

sendClassificationApprovalEmail(EmailAddress address, 
    MessageTemplate template, 
    Locale locale, 
    Classification newClassification)

What clarity could be achieved by commenting this that could not be gained by altering the name of the method or its arguments?

Around this time, twenty years ago, development environments didn't have the same kind of instant code navigation that we do today. Nowadays, if I stumble by some misfortune on a cryptically-named and mal-commented method call, I hit Control-B (yeah, intellij), and I'm instantly in the target method which I can read, understand, and (unless it's lunchtime), rename.

The comments, if there are any beyond those auto-generated by the IDE, usually reflect what the author had in mind, sort of, when he was wondering (pondering, maybe?) what it might be useful (or appropriate) for a method to do - or not do - under a particular set of circumstances (not excluding the most recent version of the spec, while taking into account what one of the users said at the last demo, although the analysts didn't agree) that may or may not bear some relation to the current situation of the project.

Steve Yegge discusses commenting more brilliantly than I could ever hope to, going so far as to declare that static typing is commenting taken to an extreme.

But I digress. The point was that without the instant code navigation we have nowadays, comments may in fact have been useful.

Configuration

Continuing our peek at pre-history, a feature of large systems in the Bad Old Days was that they took ages to compile. Ask anyone who was around. So of course you would want to pluck stuff out of the code and pop it into a config file of some sort, just to cut down on compilations.

Once you had your thing compiled, and especially if it was a native application for a popular desktop OS from a Seattle-based company, it was probably a curse to deploy. The kind of thing everybody wants to delay for as long as possible, whatever the deadline says.

So, naturally, whatever you can configure, you'll want in the database, 'cos you're not doing a redeploy just because your sponsor realised a moment too late that in fact the colour for the "to be chased" status ought to be pink, not red. Just update a row in the database, and it's done for everyone, yay!

The fact that it might cost a team-month to develop the configuration management subsystem for options that are changed, perhaps, only once a year, doesn't seem to trouble the team's goal donors however. The need for user-accessible system configuration control sometimes reflects the unhappy relationship between development teams and user teams. It says "we don't want to have to call you to make this change, you're too slow".

Nowadays the distinction between config and code is blurring. A Spring configuration file is really executable code, just written in XML. In Ruby, the distinction disappears altogether. Ultimately, there is no fundamental difference anyway - java code is just a configuration of the jvm; the OS is just configuration for the hardware. A dynamic language is what you end up with when you make your software totally configurable.

Design Patterns Considered Harmful

As for coding to interfaces and the whole Façade/Service/DAO thing, I can't fit it into the Dinosaur Theory of software development. "Teach Yourself Design Patterns in 12 Days", might be responsible, or perhaps a corporately-misunderstood two-day crash course on the topic. One important use of the Façade pattern is to hide a horrible, complex and difficult subsystem behind a single, simple, interface. The thing is, if you're writing the subsystem yourself, it's not going to be horrible, complex and difficult, right? Façade is just another way of telling your legacy colleagues, "your API sucks but I can work around that". You would just never use it on your own code!

While the goal of writing reusable code is noble and all that, the sad truth is that un-reusable code, i.e. code that solves the specific problem you have right now in this specific project, is much simpler to write and maintain. In fact, it might even be simpler to write your own thing from scratch than to use someone else's "re-usable" component. As your code grows, and as you tend your code and listen to where it's hurting, it will split naturally along implicit fault lines, and where you break a class into smaller pieces, each of these pieces will be naturally re-usable because you are already re-using them in real-world cases inside your real-world project. Designing explicitly for re-usability rarely pays off.

When I was at university, Interfaces were the thing. I got points in exams for Interfaces. But an interface covering every method for each of your business objects? Meaningless! Pointless! Clutter! Writing to an interface doesn't make your code re-usable, if the interface itself isn't re-usable.

If you have read this far, my commiserations. I'll try not do this again. Please be assured that any resemblance to any real persons or situations, living or dead, past, present, or future, is entirely accidental and co-incidental. It's not you. Leave me alone. End of rant.

21 May 2008

Respect The Machine

In a survey conducted recently (using the acclaimed dalton fast-answersTM survey technique*), most respondents claimed that respect for another human being motivates their behaviour more strongly than respect for rules imposed by a machine. More simply, people are more willing to break rules imposed by an abstract authority, than to break rules that might directly hurt another human being.

So, in Paris there are two official ways to cross the street - at painted zebra crossings without lights, and at painted zebra crossings with lights. In the presence of lights, all users are obliged by the law to respect the lights. In their absence, the pedestrian has priority.

Curiously, real-world observations reveal that pedestrians, despite having the right-of-way on bare crossings, congregate at the edge of the road waiting for a gap in the traffic to cross. The drivers appear strangely willing to co-operate with the docility of the wheelless, in what amounts to a blatant violation of pedestrian rights, in which the pedestrians themselves are complicit.

Conversely, I could spend all day pushing the button at a dedicated light-protected pedestrian crossing, and snicker as drivers patiently stop for the ensuing red light and gaze upon footless black and white road stripes until the light goes green again.

What mystery underlies this paradox? What unfathomable fountain of generosity inspires these empowered pedestrians to cede their hard-won road-crossing rights to the mobile metal capsules of our oil-addicted era? And what inexplicable well-spring of patience seizes the hearts and minds of those normally stressed and terribly late and I-don't-have-time-for-pedestrians wheel-turners so that they idle precious seconds before the useless red light of an empty crossing?

Some have suggested that the truth may be more prosaic. From the perspective of the pedestrian, apparently, it is better to be alive than to be right. Fear of a gruesome death, and not noble generosity, inspires the humble pedestrian to stand and wait while those mindless nuts behind the wheel careen past. But how, in this case, are our drivers different from terrorists? How can we say we are civilised when every minute a pedestrian's right to cross the road is crushed by a ruthless driver brutally, savagely wielding the threat of mangling your corpse under his shining wheel rims? This is not the jungle!

I think it's all a big misunderstanding, really. In fact, pedestrians shouldn't worry themselves at all. On several occasions in my personal experience cars have stopped with great suddenness so that I could continue to cross the road safely and legally. Drivers, regardless of any penalties applicable to the situation in question, will never, I have learned, never risk getting blood on their bonnets, or bits of skull in their headlights, or perhaps the paintwork scratched by a protruding fragment of fractured bone. Think of the washing-up! Peeling off patches of skin and torn flesh! The headache of insurance and other administrative formalities! No, they will screech to a halt sooner than face that. And remember, to paraphrase someone wiser than I, it is only a small 95% of bad drivers that make all the rest look bad ...**

* The dalton fast-answersTM survey technique involves me imagining what people would say if I asked them, and compiling the results in my head. The approach is wildly popular for its speed in gathering information; however, some doubts have been raised concerning its accuracy (according to another survey using the same technique)

** Always excercise utmost caution in crossing the road. Never take legal, medical, financial, or road-crossing advice from a blog. Seek professional help from qualified practitioners before making any decisions.

12 May 2008

Listening to the Customer

So one evening my son decided he wanted to program, too. This comes up occasionally, but today he was more insistent than usual. I had heard about StarLogo and that it was a language used for learning programming, so I installed it, fired it up, and stared blankly at the various panels that were waiting patiently for my input.

- but I want to program, I want to program now!!

- hold on, I'm just figuring this out

- but I want to program, why don't you let me program

- I haven't a clue how this works, will you give me a minute

And so on, until I had a wonderful insight. I fired up a text editor, maxed the font, and handed him the computer. Whereupon he merrily whacked the keyboard randomly for the next ten minutes or so.

And the moral of the story: never forget to find out what your customer wants before starting work on the solution ...

09 April 2008

mongrel_rails, ssh, and capistrano

Nothing was working. "command not found: mongrel_rails" - how could this be? It turns out that capistrano uses a non-interactive ssh session, which means the remote user doesn't get the usual environment, but rather some system default, which, as you have guessed, in my case today, doesn't include /opt/local/bin (or wherever you keep your mongrel_rails). Some commenters (eg http://www.ruby-forum.com/topic/79248) suggest tweaking the ssh and sshd configuration - but I cheated and made a smybolic link from /usr/bin/mongrel_rails to /opt/local/bin/mongrel_rails. Much simpler. At least now the error message is gone. I've still a lot of capistranoing to do though ...