Saturday, 25 April 2009

Dark Star

I’m going through a bit of a phase of rewatching/reading sci-fi that I’ve got fond memories of. Often things aren’t quite as good as I remember. However I recently watched the little known, ubercheap sci-fi classic Dark Star (1974) and if any thing it has improved with (my) age.

Dark Star is John Carpenter’s first opus – his magus opus. Mr Carpenter is better known for horror such as Halloween and the brilliant Thing. Strangely through this, his first film is sci-fi comedy. Imagine a group of early seventies hippies stuck together space and the depressed, sniping they engage in. Throw in a vague cryogenically frozen captain, a philosophical bomb and the most brilliant ending of any film. Mix it up and serve with retro Star Trek like effects and a John Carpenter synthie soundtrack and you’ve got a cult classic. And the cost of all this – to you sir it cost $60,000 to make. Fabulous – I’ll have ten.

What really impresses is that it’s downbeat without becoming dystopian like the admittedly brilliant Blade Runner or Brazil. This gives it a very particular vibe – that I can’t recall been replicated in any other film. And if all that isn’t enough reason to watch then everybody must witness the beach ball alien which bizarrely was the inspiration for the much less beach ball like and far more scary 1979 Alien.

Wednesday, 22 April 2009

The Human Clock


I’ve not worn a watch for years for reasons too dull to mention. For similarly dull reasons I’ve recently needed to embark on a dull shopping trip to various dull watch vendors to look at various overbig, overstrappy overpriced, dull as ditchwater watches before electing to purchase the least offensive of the bunch. Dull, dull, dull. Dull and pointless indeed when you consider the timekeeping excitement which is the human clock.


Rather than a boring old circular watch face with some numbers and pointy hands the human clock tells the time through the medium of well … humans. Every minute of every day is displayed by a new piccie that someone has sent it. From the routine street numbers, to birthday cakes, to patterns in the snow to car registrations – every field of human endeavour is used to tell the time. It’s a humanist marvel.

So throw out your watches people and tell the time through the medium of the human clock. In fact in these wireless times it wouldn’t be too much of a stretch to fashion a watch type device that would display the human watch where ever you are - the iHumanClock. Come on Apple, make it happen.

Saturday, 18 April 2009

The Power of (C# Keyword) As

I’ve been coding in C# now for 5 years. Other than with my wife, C# is my longest standing relationship. While I don’t celebrate my anniversaries with C# (yet – though I might on our 10th) I did think that I was familiar, maybe even intimate, with the language. Why then had I never heard of the as keyword.

Previously I would cast object like so
try
{
Checkbox myCheckBox = (Checkbox)strangeObject;
//do some clever stuff
}
catch(Exception)
{}
- which works fine. My niggle with this that you’re getting towards using exceptions to manage the flow of code and the seven circle of hell is reserved for coders that indulge in this satanic practice. Enter the angelic keyword as

Let’s do the same thing, this time with our new friend.
Checkbox myCheckBox = strangeObject as Checkbox;

if(myCheckBox != null)
{
//do something clever
}
The as casts the object but instead of spewing out an exception it gracefully nulls it. Therefore it’s same code but with no exception unpleasantness. I like this a lot better – it’s like wholemeal fibre vs. saturated fats. It’s just a lot better for you.

Saturday, 11 April 2009

Visual Studio Short Cuts

I would like to urge all .Net coders to follow my new one a day program. Following it will guarantee health, well-being and popularity (possibly) and will be the beginning on a new phase in your life. It’s nothing as mundane and tawdry as one piece of fruit a day, one session of exercise or one kindly action to a stranger. It is a commitment to learn one new Visual Studio shortcut a day for the next two weeks.

Trivial, perhaps. Overstated, almost certainly. However a few more decent shortcuts under your belt will make it seem you’re directly interfacing with your IDE in a scarily symbiotic way. You’ll be faster, more efficient and far more popular with the opposite sex. Particular if the opposite sex is your project manager to whom you’re delivering software to that bit faster.

Wednesday, 8 April 2009

.Net Control Collection Gotcha

Making puff pastry is something that sounds like it should be easy but when you’ve got the butter, flour and mixing bowl out it turns out to be excessively difficult. In the same vein – iterating through a collection of .Net controls and finding all the ones that are checkboxes sounds straight forward but is in fact a bit of a pen chewer.

My first attempt. This is a winner surely.
foreach (Control control in thisPanel.Controls)
{

if (control.GetType() is CheckBox)
{
//never going to work
}

}
Nope – the compiler complains straight away that ‘Control control’ will never be of type checkbox. OK sounds reasonable. After some discussion with colleagues a fellow programming minion suggested that it’s the foreach that’s the problem – so try the following.

for (int i = 0; i < thisPanel.Controls.Count; i++)
{
if (thisPanel.Controls[i].GetType() is CheckBox)
{
//won’t get here either
}
}
Looking good – but sadly again won’t work. The problem is that the control collection has already been downcast to a generic control. Therefore it doesn’t ‘know’ anything of its original type. What’s a boy to do? The best 4 programmers could come up with a combined amount of programming experience of over thirty years was –
foreach (Control control in thisPanel.Controls)
{
CheckBox checkBox = control as CheckBox;

if (checkBox != null)
{
//now we can do something
checkBox.Enabled = false;
}
}
This solves the problem so hurray. I have a nagging feeling that there is a better solution. It seems a simple request that should be achievable without guessing what types are in there. It’s probably something wildly clever with generics/delegates/lambda expressions or some such. Further pondering required I think.

Saturday, 4 April 2009

Spelling and Software Quality


In Charles Dickens' Hard Times, the severe Mr Gradgrind teaches children “Facts. […] nothing but Facts. Facts alone are wanted in life”. In a similar vein I would like to teach computer programmers “Spelling, nothing but spelling. Correctly spelt words alone are wanted in computer programs”.

I may well be a pedantic, mean spirited, weasel coder of a man but badly spelt words in software code drives me crazy. There is more to it then my love of order, rules and finding any old stick to beat other coders with. Spelling mistakes in code have the half life of plutonium. If some one spells a word wrong in an email it doesn’t matter. It’s sent, it’s read and it’s gone in an ephemeral puff of cyber smoke. If someone spells a variable name wrong in code it will lay around in that app like a bad smell for years. And if some creature of great evilness spells a database table wrongly – the universe will undergo its final heat death before anyone gets round to correcting it.

It’s more evil still then just poor use of the English language offending me on a daily basis. It’s a software maintenance nightmare. At a minimum the poor maintenance coder has too remember exactly which variant of the word “category” is been used this time. At its worst seemly innocent typos cause redundant code to proliferate like rampant triffids.

As a recent example I came across are these stored procedures

usp_GetPersonelDetails
usp_GetPersonnelDetails

OK – which one is the correct one to use? Either, both, neither? Which one can I delete to tidy up? Which one is the most recent version? Which one will cause the app to fall into a smoking heap if used? Aaahhhhhhhh!!!!!!

So as well as unit tests, regression tests and usability tests, I prescribe spelling tests to push back the ever encroaching waters of crappy code.

Wednesday, 1 April 2009

Rapid Development

Of all Steve McConnell’s books, Code Complete gets the attention. People quote it, name websites after it, publish photographs of themselves kissing it and generally froth and foam about it. And quite right too because it’s great. However for my money his book Rapid Development is even better.

Although called Rapid Development, its name is something of a misnomer. It’s not about rapid development techniques per say, rather it’s about excellent project management techniques that as a side effect will enable your project to proceed as quickly as possible. To me it feel’s like its project managers written for developers.

If you don’t want to read it cover to cover (what’s wrong with you – read it all) then software estimation, the sections on motivation and team structure and classic mistakes are worth reading as standalone chapters. I love the estimation tables provided to measure your own schedules against. It’s illuminating to measure your own projects against them. So next time an impossible deadline looms, you’ll have the facts to back you up. Marvellous.