Sep 28, 2010

Please, don’t do it!

I was working with some legacy code a couple of weeks ago and I came across a little gem that deserves some bits on the wire. Le this serve as a cautionary tale for all developers out there.

The story dealt with extracting a document from a legacy database and displaying it in a new application. Fairly easy task one might be tempted to think. Wrong! After some trials, tribulations and perusing some very convoluted legacy code we track down the offending piece of code. What we found was… well… it defies qualification; or maybe I’m just not good enough with words. !#@$@@%! There, that’s better!

Somebody decided that they were missing out by not using this cool feature called XML, so they took their HTML document and stuffed it in an XML document. Cool right? NO, that is NOT cool dude!

Than there was a need to add more HTML documents in the XML document. Easy, just add another node and store it in there. Even cooler, right? NO, that is seriously not cool dude! Maybe we should backtrack a little at this point. If you had a pair they’d be smacking you over the head with the heaviest book in reach by now. Or just not allowing you keyboard access for the next day or so.

Now all of this XML/HTML data is consuming a lot of storage space on the server. We should probably compress this sucker. Really? Have you looked up the cost per gigabyte lately? And while we’re at it we should use the most obscure compression algorithm ZIP supports, Deflate64. This thing is going to be awesome!

Finally, this data needs to at least be easily accessible and query-able. Let’s leverage an RDBMS and store the compressed XML document that contains HTML in a binary format. That will make the task complete!

My only question is: Really? Why would you do this to yourself? The moral of the story is that your coworkers will get upset, angry and might have random emotional outbursts when dealing with this kind of code. If you find yourself contemplating storing HTML inside and XML document, compressing it and than storing it in the database, PLEASE DON’T DO IT!