Saturday, 27 December 2008

Technology after the Crunch


I was listening to ‘Analysis’, a BBC Radio 4 podcast about the credit crunch. It turns out that giving people six figure bonuses to destabilise the banking system isn’t the best way to run a modern economy. So given that driving the economy via financial services has ended in collapse and misery, the question being asked was what should replace it?

The answer was that we should get back to what we are good at – technology. The argument was that finance has gone too far, other countries do basic manufacturing better and cheaper (admittedly by working children 14 hours a day with no toilet breaks) and we’re not suddenly going to start exporting huge quantities of basic commodities. So technology will be the new driver.

So good news fellow tech nerds. When the dust settles on the credit crunch we will be the new investment bankers. So say farewell to tiny monitors, rickety office chairs and crappy vending machine coffee and say hello to corner offices, chair massages and ludicrous annual bonuses. It’s Aston Martins’ all round. So when I’ve finished delivering a minor website upgrade I see you all in the champagne bar for a 4 day celebration. It’s only what we deserve.

Thursday, 25 December 2008

The Long Day's of Christmas


I once worked in an office where the boss didn’t understand the concept of Christmas. He wasn’t scrooge like – because scrooge acknowledged the existence of Christmas. My boss didn’t even go that far – he just wasn’t aware of it at all. The Christmas season would run like this -

On the First Day of Christmas my PM gave to me
A new spec for a shiny app

On the Second Day of Christmas my PM gave to me
Two day’s training
And a new spec for a shiny app

On the Third Day of Christmas my PM gave to me
Three pep talks
Two day’s training
And a new spec for a shiny app

On the Fourth Day of Christmas my PM gave to me
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app

On the Fifth Day of Christmas my PM gave to me – five change requests
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app

On the Sixth Day of Christmas my PM gave to me – six bugs a breaking
Five change requests
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app

On the Seventh Day of Christmas my PM gave to me – seven clients complaining
Six bugs a breaking
Five change requests
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app


On the Eighth Day of Christmas my PM gave to me – smoke tests a smoking
Seven clients complaining
Six bugs a breaking
Five change requests
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app


On the Ninth Day of Christmas my PM gave to me – nine weekends working
Smoke tests a smoking
Seven clients complaining
Six bugs a breaking
Five change requests
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app


On the Ten Day of Christmas my PM gave to me – ten releases cancelled
Nine weekends working
Smoke tests a smoking
Seven clients complaining
Six bugs a breaking
Five change requests
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app


On the Eleven Day of Christmas my PM gave to me – eleven coders weeping
Ten releases cancelled
Nine weekends working
Smoke tests a smoking
Seven clients complaining
Six bugs a breaking
Five change requests
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app


On the Twelfth Day of Christmas my PM gave to me – a twelve week extension
Eleven coders weeping
Ten releases cancelled
Nine weekends working
Smoke tests a smoking
Seven clients complaining
Six bugs a breaking
Five change requests
Four tight deadlines
Three pep talks
Two day’s training
And a new spec for a shiny app


Merry Christmas!!

Wednesday, 24 December 2008

Dr Who and Gender Reassignment


It’s as seasonal as Turkey, Santa Claus and squabbling with relatives. The Christmas special of Dr Who is on BBC tomorrow and it should be a particularly special special since Mr David Tennant is stepping down from Timelord duties. So who will be taking his place in the swirling time vortices of BBC central? The smart money at the moment appears to be on David Morrisey with Robert Carlyle on the outside track. While these are both worth recipients of the keys to the Tardis I want to give a shout out for Tilda Swinton.

I truly believe Ms Swinton would be a timelord to remember. She played an excellently disturbed turn recently in Michael Clayton and her other worldliness is without question after her performance as the Angle Gabriel in the otherwise average Constantine. She is stylish, elegant and an excellent actress. So who could be better for the most important role of our age?

There may well be nay sayers who point out that Ms Swinton is in possession of an awkward set of XX chromosomes. I say being a lady of the female persuasion is no problem. Firstly, she is no stranger to androgyny. The aforementioned Angel Gabriel was a fella angel and the more seasoned Swinton watchers among you will remember Orlando - the entire premise of which was based on shifting sexuality. Secondly, this is science fiction. Someone changing gender a little bit is hardly beyond the realms of what goes on in the genre. So long as Dr Who doesn’t descend into Deep Space Nine levels of ludicrousness then that’s OK by me.

Furthermore Tilda meets the most important prerequisite for Doctorhood. She is British. Whilst I think that most Whovians would quite happy to accept a bit of gender reassignment during a regeneration – if the Doctor was to become more trans Atlantic then thousands of geeky sci-fi fans would recoil in horror. An American Doctor would be a step too far. It would see us putting down our Games Workshop bags, manning the barricades and throwing our shoes at George Bush.

Saturday, 20 December 2008

Self Documenting Code – Gimme Just One Less Line

I was in a technical interview a good while back and it was review your answers to the tech quiz time.

INTERVIEWER: OK, that’s a good answer. That would work but can you do it in less lines of code
ME [chewing pen]: Errmmm –OK that’s it in two lines
INTERVIEWER: OK – but I’m sure you can do it in one line
ME [scratching head]: Oooooo – Errmmmm – that’s one line
INTERVIEWER: Well Gee – that does it. But I’m sure you can do it in maybe 10 characters
ME [Weeping real tears]: Ahhhhhhhh !!!!!! Please let me out.

OK – maybe the end of the interview went a bit better but I must have spent a good 20 minutes frantically trying to trim down my code to the size of an atom. I retrospect I think it was a fair enough way to grill me – but in the day to day work of chipping away at in the salt mines of computer code do you ever want to trim your code down to the bare minimum?

Consider this code
private static string RemoveTrailingTag(string input, string tag)
{
if (input.Length >= tag.Length && input.Substring(input.Length - tag.Length) == tag)
{
input = input.Substring(0, input.Length - tag.Length);
}
return input;
}
OK – it’s trimming tags from strings. But what on earth is the 'if' statement doing. The revised code tells us
private static string RemoveTrailingTag(string input, string tag)
{
if (HasTrailingTag(input, tag))
{
input = input.Substring(0, input.Length - tag.Length);
}
return input;
}

private static bool HasTrailingTag(string input, string tag)
{
return input.Length >= tag.Length && input.Substring(input.Length - tag.Length) == tag;
}
OK – the ‘if’ checks for the trailing tag. Admittedly I’ve expanded the code but I’m a big believer in more is less (confusing). Of course self-documenting code isn’t new (Steve McConnell etc..) but there does seem to be a real mind set of trimming code down to the smallest, most elegant (i.e. unreadable) fragments. It’s as if we’re developing assembler code to run on the chip of a washing machine. Except most of us aren’t and never will be.

Wednesday, 17 December 2008

Flow

There’s all kinds of advice around for career development in IT (career calculus, coding horror, red queen) but if I really think back to projects that have gone well when I’ve received a pat on the from the boss du jour – it seems effortless. I haven’t waded through treacle and hacked away the woody vines of confusion to get the outcome – it’s just happened. I’ve felt energised, focussed, in the zone – I’ve been in flow

Flow is a psychological state when concentration is easy. It’s the time when you lose yourself because the task is so absorbing. It’s the time when you look up and everyone has gone home except the office cleaner and you didn’t notice. It’s the time when you LOVE your job. I contend that to truly be a great developer you should aim to spend as much time as possible in the groove i.e. in flow.

There are certain things from a task perspective that can encourage this. The task should be challenging without been overwhelming. It should have immediate feedback (software development provides this in spades), have a clear goal and you should have a measure of control over it.

Unfortunately many of us for much of the time don’t have control over our individual tasks at work. So are there ways an individual can broaden there capability to go into flow? Michael Buffington gives some tips but interestingly practicing martial arts, yoga or meditation have been linked to increased flow states. So if you want to do well in your job you could work late, read a new text book and offer your wash your boss’s car. Alternatively you could take up karate, buy a yoga mat or meditate before work.

Sunday, 14 December 2008

DataTable Filtering Gotcha

The mission – if you choose to accept it is to filter a .Net DataTable to return results from a year or more ago. The code is
DataTable dtDataTable = GetDataTableMethod()

//.. limit the dataset
DataView dvDataTable = new DataView(dtDataTable);
dvSurveyList.RowFilter = "DateField < '" + DateTime.Now.AddYears(-1) + "'";
Our spies tell us that it doesn’t actually work. Agent tech splurge what is the solution? Stand well back folks while I insert the missing line.
DataTable dtDataTable = GetDataTableMethod()
dtDataTable.Locale = CultureInfo.CurrentCulture;

//.. limit the dataset
DataView dvDataTable = new DataView(dtDataTable);
dvSurveyList.RowFilter = "DateField < '" + DateTime.Now.AddYears(-1) + "'";
To me this makes sense. If you’re playing with dates then you’ll need the culture information – dates being different in different cultures. The odd thing is that the first set of code worked perfectly – until it stopped working. I have to confess I still don’t know why.

Wednesday, 10 December 2008

Software Estimation for the Courageous


In days of yore a man used to prove his bravery by a mighty quest for a fair maiden, the slaying of a ferocious dragon or by acts of great swordsmanship on the battlefield. Sadly in modern times these opportunities rarely present themselves to the average software developer. But fret not stout of heart – there are still ample opportunities for bravery without moving away from your monitor. Simply give an estimation of how long a software project is going to take using the following methodology.


I truly believe that software estimation is blackest of all the black arts in software development. Entire books are (quite rightly) written on the subject.


The best and simultaneously the worst advice I’ve have ever read about estimation comes from Crash – Learning from the World’s Worst Computer Disasters. Quite simply - sit down in a quiet room with a bit piece of paper and a large mug of coffee and truly and honestly work out how long you believe the project will take. Miss nothing out. Remember the testing, remember the deployment, remember the reworking, remember it all. Then TRIPLE it. No matter how bleak the answer looks – bravely go out and tell your project manager. He/She will not thank you for it. They will request re-evaluations, ask second opinions and doubt your sanity. You may be sidelined, sneered at or send off in exile to the build team. You will be tattered, torn and unloved but you will be correct.


If you are brave then try this. I did once and it caused a career damaging fight between the head of development and the project manager. The project manager left, the head of development sulked but the work was delivered in the (tripled) timescales that I said. I was unloved but correct. I was brave. I never did it again.

As an addendum to this – a far better way of estimating projects would be to actually start to build historic data in your company as base predictions on that. Steve McConnell gives excellent advice on this in Rapid Development. The moral of the above little anecdote is that it’s not enough to be correct; you have to be correct and believable - and that takes evidence.

Saturday, 6 December 2008

T-SQL Identity

This is probably as old as the hills but I still see this everywhere. What’s wrong with this line of T-SQL
Declare @PrimaryKeyVariable int
Set @PrimaryKeyVariable = @@IDENTITY
Nothing until it gets deployed into a high volume usage situation and the number of users ramps up after a few months. Then it will blow up and someone will be in at 3a.m. desperately trying to restore the referential integrity of the database.

The problem is that it will set the variable to the most recently set identity flag in the database no matter who has done it. That might be you or it might be another connection – thus linking up/deleting/updating the wrong records. If you’re lucky the transaction will fail. If not then you’ll be digging around in those two hourly transactional backups to get it back. Oops.

And the answer is really straight forward. Just use this instead
Declare @PrimaryKeyVariable int
Set @ PrimaryKeyVariable = Scope_Identity()
The identity is now only taken from current connection. It’s scoped – just like mother always used to scope her identities. Lovely.

Wednesday, 3 December 2008

The BMA, BCS and the Devil


It’s said that the best trick the Devil ever performed was convincing mankind that he didn’t exist. In the same vain the best trick the British Medical Association (BMA) performed was convincing the British public that it’s not a union. The BMA appears to style itself as a professional body that’s only concern is for patient welfare. The doctors that I have personally known are more of the opinion that it is a highly efficient union getting the absolute best deal for its members. I have nothing whatsoever against the BMA, in fact I wish we had a bit of that in computing. But instead we have the British Computer Society (BCS).

I’m sure that the good people at BCS believe they are doing their very best to professionalise the computer industry. However the fact remains that I have never met anyone who professes to be a member let alone speaks of the BCS in glowing terms. Never …. Ever.

Play this game with your family and friends. Which one is the odd one out? The BMA, The Law Society, The Royal Institute of Charter Surveyors, The Mafia, The British Computer Society. Answer – the BCS because the rest actually seem to do something for their members.