RaymondBerg.com

I played buck the other day with one of my coworkers. You know, slamming heads together until the one with the weaker cranium backs down. But it wasn’t over a food supply or even a girl. This time it was over development standards. Unfortunately, I lost because of the laws of hierarchical office structures, even though I have a rather resilient forehead.

The Issue:
ANT build scripts don’t have error throwing if a variable isn’t defined. If an undefined variable is used, it will be used as a string literal instead of a variable (ex. ${my.name} if defined outputs ‘Raymond’ if not ‘${my.name}’).
The Scenario:
Our build script does a find and replace of 4-6 sets of information including server names and logical domains. Conditions currently split each find and replace into separate functions, each one executing only if the ‘find’ variable is set.
The Manifestation:
If the ‘find’ variable is set but the replace variable isn’t, the ‘find’ string will be replaced with the string literal format of the variable.
My Issue:
No error is thrown. We are taking potentially invalid input (i.e. find set but replace is not) and breaking it as it passes through our code. If we would replace with a null, that could almost be expected, but we’re replacing it with constant strings from inside our code.
My Solution:
Add additional check to make sure both inputs (find, replace) are set. If not, skip the replacement. If they don’t have something to replace the string with, then you don’t get to replace it: simple and effective. There’s more possible, but it’s a functional build script. Remember to KISS.
Not my Solution:
Tell the users to be sure to have all fields set. If they don’t then it’s their fault.

So what’s the easiest way to handle this simple disagreement? Put yourself in the user’s shoes. Suppose someone handed you an executable to manipulate your files. You supply them with the information you’re looking for and what you’re supposed to replace it with. One day, you forget to enter a value for one variable or it gets deleted while you’re shuffling a file around. After using it, you look at the output, and see a large constant you’ve never seen before : “sys.alias.cro#-n55!s” has replaced the text you searched for.

Did the software work according to it’s purpose? Was the functional mapping of input to output logical? If I insert a null field as input, would I logically expect this output? What documentation should I expect to find? How do the developer’s explain this functionality?

On the flip side, this build script is a stop-gap, and it’s only going to be used by the developer. So that makes it alright, right? Wrong! I’ve been witness, time and time again, to situations where the code IS STILL USED. Including 10 year old legacy systems written on Access Tables, batch scripts that are acting in between huge and complex databases. And if it’s not being used, then someone else is learning about the language from the code you wrote. They’re picking up your habits or copying code into their own documents.

I don’t have the keys to the programming arcana any more than I have the ability to safely swing a lightsaber. But it doesn’t take much to check yourself against your consumer. And, if you take the advice of an amazing article from Coding Horror, you’ll realize the goal isn’t to make software just for someone else to use.

Posted on March 21st, 2008 | filed under Uncategorized | Trackback |

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    follow me on Twitter