Thursday, 23 May 2013

The Agony of a Defensive Programmer

By nature I'm a defensive programmer, a good example is whenever I use C++ I want to force wrapping of my classes as smart pointers, by making the constructors private and only giving a static factory create function, which returns a smart pointer wrapped copy of the pointer to the new class each time...

So, when I'm left to pick up the pieces after a non-defensive programmer is pains me immensely... Not least when the situation is an obvious like a file load.. Here's the gist of the problem, I'm not being specific, but lets assume:


if ( File.Exists(m_Filename) )
{
Load();
}
else
{
Create();
Save();
}

Now, if the file isn't there, you make a copy... And save it, whenever you come back you load it... "What's wrong with that?"

Well, the load function, lets take a look:

void Load ()
{
DeserialiseFile(m_Filename);
}

So, it just tries to read and deserialise the whole file?... yeah... and still not seeing the problem?

If you don't see the problem, a small part of me weeps for you... For the problems are many, and annoying, and mine to fix when you stroll off and leave this code as acceptable.

i. What if the file is corrupt?
ii. What if the file format changes?
iii. What if someone has saved a file with the same name?
iv. What is some sneeky so-and-so has saved a fake file there to try and force your system to do something strange?

All these problems, cause a crash of the attempt to DeserialiseFile, and so bring the program to its knees...

So what would I, the defensive programmer done?  Well, how about:

void Load()
{
try
{
DeserialiseFile(m_Filename);
}
catch (Exception l_e)
{
Output/LogError(l_e);
}
}

So, now the program doesn't crash, and you can detect out of date formats, or erroneous files, or corruption...

There are better solutions than this, but this isn't even my code, so I'm forced to do the bare-minimum to "fix" it, and to fix it I'm literally just catching & logging the problem, and then carrying on.

Wednesday, 22 May 2013

Hidden in Plain Sight (DLLs & Documents)


There seems to be a penchant from software to hide its true ability, to obfuscate the obvious and even publicly visible guts of itself, anyone whom has had to program - properly program - for the windows platform will know what I'm hinting at... All those little hidden nuances, undocumented features, or flat out bugs.

This isn't to say all of them are hidden, or secret, but lots of things are.  Either through being close source software, or whatever you want to call it, but point of fact is, if you publish an interface for people to use and in that interface they can see many many things, you need to document them, even if your document warns people off of them.

By not documenting them you're not going to keep people from seeing them, they're there, and you're not going to stop  people poking and prodding them.  So, what are you achieving by pretending these kinds of things are not available?  Or not there?

Lets look at a case study... You are working for "Software Matic Corporation" and you release the new "SMC Interface" as a dynamic link library, and in that library's documentation you list the calls you want people to use, and they are:

"Connect"
"Disconnect"
"GetStatus"

Three, pretty innocuous calls, and you document not to call "GetStatus" before "Connect" and not to call "Disconnect" too soon and all the other rules.  And you shuffle this out the door for release.

Then Mr Software user at the other end, opens your dynamic link library and takes a look and he see's other calls... like;

"TellSMCSecrets"
"FormatHarddrive"
"CrashSystem"

And he starts to poke and prod these calls you never mentioned, and never intended anyone to use, and what happens?... Well, at the worst case Mr Software guy crashes his software or ruins his machine.  But will he blame his software?  Or will be blame your DLL?...

After all YOUR software call caused the problem... YOU released software with that call in it... YOU put it in the public interface!

You never intended the calls to be used, so they should not have been exposed in the public interface, not simply omitted from the document, omitting from the document is just wrong, its the software equivalent of denying the sky is blue (note: the sky is blue folks).

And if you Do put something in an interface like this DO put it in the document, don't exercise this penchant for omitting things.  Even if you only give is cursory "PRIVATE FUNCTION DO NOT CALL" note, its better than risking the ire, or even bad PR which comes from not mentioning something which is sat right there begging to be used.

Tuesday, 14 May 2013

Outlook mail is a joke

I've been sat waiting to try and read my mail for over 10 minutes, I can see the mails, see who they came from and their topics.  But can I read them?  Can I hell....

Whenever I click on a mail is just sits there, and if I try to change into any of my alias accounts linked into this one then they do nothing they just show me that damned annoying three white dots whizzing in from the left and out from the right at the top... and its doing nothing.

Surely the point of mail is to show me the fucking mail, but it seems not, not in Outlook world.  I in fact think it needs changing from Outlook to In fucking Look, cus the bastard thing can't do what I need it to do.

And what's worse is, I didn't choose this mail, they forced it on me, I chose MSN over a decade ago, and I then settled down to their enforced change into Hotmail, but at least MSN and Hotmail both worked, these Outlook servers are just rubbish.

I've tried lots of things to get this work, I've tried using Chrome, then used IE to pacify the system, then I've tried from work, from a mobile device, from home, from wired, from wireless, from Windows 7, from Vista, from XP, from Linux... None of it my end is wrong it all works, and all used to work with Hotmail, but this new server is for shits.

Is that George?

Is it me, or does the narrator of this really really sound like George Carlin?


Telephone Manner


Its not often I get to speak to suppliers or customers that often any more, I used to all the time, and I cut my teeth in IT talking to the lovely people at Sco and NCR and AT&T being nice to them to get what we needed on a shoe string budget.

Anyway, its been a while since I was in any such position, and so it was a happy moment today when I had to speak to a support operator (a quite senior chap) at 3M about a problem we had with a device we're interfacing with.  The essence of the problem was that we're using the off the shelf driver on Windows, and we need to make it do a none-standard operation, an operation which currently requires a reboot - we just want it to do this operation without needing to reboot the whole machine.

A nice chat of a few minutes and voila, he's on the case and he was lovely - 3M good on you!

The interesting thing however was, as I came off the phone, three different people were staring at me... "You sounded dead posh"... one of them said... "Professional"... said another... "Like you were so polite and nice".

This has me worried, I thought I was always like that, and always have been... But it seems my telephone manner has been missed around here, I might start to talk to everyone in my telephone voice, it got such a big reaction I might just act like I'm doing Shakespear at work. lol

Monday, 13 May 2013

The Stink

Here it is, for days, weeks I've been sitting here in the office saying... "SOMETHING SMELLS OF FARTS"....

I've looked all around my desk, I've checked the air vents, I've checked the window seal... No idea what it is...

Just now, I had enough of it, I was alone in the working area, and I could smell it... No aircon, nothing... The airs getting thicker and thicker with it.  So I open the window, and take a fresh air break.  Close the window and turn around... WHAFT!

So I start going like a blood hound... and I'm going... Sniff sniff sniff....

Not my desk... Not the other desk, not the machines... not the bin... The desk by the window.. sniff sniff...

Not the chair, not the draws... Sniff... Retch, the fucking plant.

The potted plant was rotting away... The guy has not been in in a while, but we leave the desk alone... and... sniff... fucking hell.

I take it to the kitchenette and lift it out the pot, and there's dried black scum all over the inside of the china pot, and then no water... So I wash the pot, and wet the soil... Whaft... OH GOD.... The smell once water hit the soil, 100x worse... Which is a bit of a laugh because the poor schmucks sat closest the kitchenette can do nowt but smell it now...

Its a little pay back, I've had that smell for weeks...

I've sorted it, and sprayed the whole office with air freshener, but still... drama.

The ironic thing is, I often describe the atmosphere in here as "being like a used trainer"... but I'd have taken the smell of an old Nike over this stench any day.

She's Drunk

Sounds pretty drunk to me...


Pretty damn hammered, jolly hammered, not vomit in the tulips, "Giz a Kiss" hammered, more... bang my hands on the desk and present a shit show drunk.

I like my local radio, I enjoy BBC Radio Nottingham, but if this were local I'd be ashamed.