Wednesday, June 11, 2008

Ninja Secrets of Software Development

I spent a good portion of today writing a filter, to prevent some destinations from being sent certain types of messages. I was essentially making a quick hack to cover for a failure in another group, the developers of the code at the destination that would incorrectly handle the messages. So I was having to write this fairly quickly, and get it into a testbed ASAP, so it could be verified as working, and sufficiently flexible to serve for the (hopefully) short period of time before the destination code is fixed.

The fact that I was having to read from a configuration file for the ID of the destinations to filter made me realize that a Software Ninja should follow the historical example, and have a bag of tricks handy for just such an emergency. When surprised by a pop-up deadline, the Software Ninja can throw caltrops on the trail to slow down pursuit, and escape. In this case, the caltrops would be snippets of pre-packaged code that can be quickly pasted into the project to solve the immediate problem, and later improved or removed as desired.

These snippets are not necessarily code residing in the project itself, but a collection of functions, methods, classes, and whatnot, kept in your private workspace, that you can use to mold changes in the project code when there is no existing code in the project to work with. It should be in whatever languages you develop in, and as you go, glean more from the project. You're looking for common small tasks that span all types of projects.

In my example, I needed to read a text file produced from a database unload, parse it into fields, and save some of the fields for later use, in a collection that resized as needed. It's teh type of routine you find in many projects, so I will add it to my bag of tricks.

And you can generalize them a little. It's quite common for the data source to change as a project evolves. It starts out as a flat file, grows to a CSV file dumped from a spreadsheet, then to a database table. Your snippets can relate to each other - have a flat file reader that can parse fields separated by arbitrary characters (strtok_r is your friend in C++, as split() is in Perl and Python), and a database table reader that pulls fields out of a table, and they feed into a routine that returns a dynamically-sized collection. If you're writing in Java, you may need a routine to read in properties files. For shell scripts,
a whole set of routines for reading from files, accessing databases via SQL, or grabbing a web page with curl may suit your needs.

So keep an eye out for useful snippets, and grab them for your collection. And the next time a manager springs a deadline on you, your Ninja response will throw pepper in their eyes and escape into the shadows.

Technorati Tags --
, , ,


Brian Tkatch said...

I don't understand the comparison. Caltrop's and pepper slow the attacker to give the defender more time. The bag of tricks is more about being ready for everything.

Though, having a library is an excellent idea. Besides helping to speed up future cases, it teaches the coder to think in general, and not just get this one item done. As you said, the incoming format may change.

Dixie Software Ninja said...

"Dammit Brian, I'm a Programmer, not an Analogy Maker!"

The point of the analogy is that you can evade the deadline's effect by having something ready to use that will solve the problem, much like the historical (and folkloric) ninjas had the caltrops, eggs full of blinding powder, shuriken, etc, close at hand for defusing pursuit.

In other words, I'm beating an analogy out of shape to suit my purposes.

Brian Tkatch said...

Heh. I know.

But couldn't you spend at least a second or two on it? I think it better to not use an analogy than to come up with one that doesn't fit.

BTW, i liked the post. Which is exactly why the bad analogy bothered me. :)

Dixie Software Ninja said...

Brian, I guess I'm seeing the caltrops/etc as a specific item in the bag of tricks. That said, what sort of analogy are you thinking would get the point across?

ALso, thanks for being the first person to post more than one comment!

Brian Tkatch said...

So i'm the first guy duped in your blog? :P

An analogy for being ready? Batman's utility belt? The best example i know of is having a code or script library. In the few moments i have taken for this comment, i don't see a better one.

Dixie Software Ninja said...

While I like the Batman utility belt idea, it's not my
<"Idiom, sir!">

my idiom, yes.

Brian Tkatch said...

Nor mine. Perhaps i will find a better analogy. This may be a good puzzle. :P