dreadedmonkeygod . net

Poor Trade-Offs

I keep running into errors like this one:

org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. 
        at org.apache.xerces.dom.CoreDocumentImpl.createElement(Unknown Source)

Now that's just lazy coding. It appears that I've tried to create an XML element with an invalid name. What was the invalid name? No clue. And I'm trying to create the XML from a series of SQL queries, which were retrieved from .properties files and fed into a custom implementation of PreparedStatement, so I'm going to have to do some digging before I discover the source of "invalid or illegal XML character."

How much nicer it would have been to see:

org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: "3" is not a legal element name.
        at org.apache.xerces.dom.CoreDocumentImpl.createElement(Unknown Source)

Now I can take a pretty good guess as to where that idiot field name came from. (As it turns out, it was from a JDBC driver that "helpfully" supplied the column numbers in the event that no column name was specified in the SQL query.)

This may seem like a small thing. But it isn't. Debugging takes longer than coding. The Mythical Man-Month (if I recall correctly) suggests that it usually takes five times as long to debug a project as it does to write it.

So if I double the programming time, and cut the debugging time in half, I don't break even. I save a mountain of time. I spend an extra day coding, and can shave 2½ days off the debugging time, that's a good deal.

Plus, spending time on debugging only pays off once: debugged code. (And remember: it's just had the bugs you know about removed!) Investing in making my code easier to debug pays off every time I make a change. Over the lifespan of a project, that extra hour I spent improving the error messages in my code might mean I save me weeks of digging through stack traces. (Which in turn means I can get by with a weaker eyeglass prescription in my old age.)

So, when I see error messages like "invalid character found", I can't help but curse the programmer who couldn't take an extra two of minutes to make his code easier to work with.

Remember kids: you only have to write the code once. You're going to have to read it, change it, and debug it many, many times. Taking shortcuts to speed up coding at the expense of maintainability is just a bad trade-off.

Post a Comment

Name:
Email (Never, ever displayed.)
URL:
Remember me next time.
Comments (Sorry, no HTML allowed. Space paragraphs with a blank line.):