February 10, 2007

Wrapping my code in Kevlar

I spent most of this week making my code as bullet and monkey proof as possible. Even though the very small number of people who will actually use the application are unlikely to do most of the things I was coding against, I need to get past the people in my development team who will be testing it first. And one of them is a self-professed 'fat finger' who will hit random wierd key combinations occasionally. By the end of the week I was slamming my fingers against the keyboard in random ways and trying various non-alphanumeric keys just to see if I could get the app to bomb. It took a lot of time, sleuthing, testing and patience but I think I'm pretty much done. We'll see what my team says next week.

Last night I threw the search string "programming bullet proof code" into Google to see what it came back with. The second hit was the blog Call Me Fishmeal and an entry called Free programming tips are worth every penny. In it the author, Wil Shipley, wrote it last February, but some topics are timeless. Shipley offers advice to other programmers in a style he calls The Way of the Code Samurai

Don't gloss over anything. Write every line to be bulletproof. Write every method as if every other method was out to get your code and try to make it crash, and your job was to make sure it wasn't going to happen in YOUR code. Assume the user is going to hit keys randomly. Assume the network is going to get disconnected. Assume the hardware will fail.

That describes what I've been doing pretty well. It results in some ugly code at times and I'll need to go back and pull some of the repetative validation into functions, which will help shrink the code and make it a bit easier to understand. Shipley addresses refactoring as well:

There's a time and a place for optimizations...

- The time and place are AFTER YOU ARE DONE. Optimize methods ONLY after they work and are bulletproof AND you've done testing in Shark and discovered the method is critical.

It's a good read for those interested in other peoples ideas about how to improve as a coder and he's got other entries about that subject as well.

Posted by buggy at February 10, 2007 10:41 AM