When bad programming cliches turn out to exist after all

Sunday, August 5th, 2007

I’m a frequent reader of the curious perversions in information technology blog Worse Than Failure (previously The Daily WTF). Each day they share new horror stories from the realms of IT, including abominable code snippets and and nearly unbelievable tales of woe from the IT sector. I follow it closely. Two themes that seem to be coming up again and again are overuse of XML and overuse of design patterns. XML is good at what it was made for, but a lot of coders seem to think it’s the best thing since sliced bread, and use it in all sorts of situations it isn’t appropriate for. Design patterns are a way of coding that seem to emphasize form over function, and the majority of the lines of code in a design pattern-heavy program just end up passing around objects from one place to the next.

I thought of these perversions of information technology as being “over there”, you must understand. Little did I realize that I would very quickly be confronted by these two bad programming cliches within two weeks of joining the workforce, and not only that, I saw them in the same piece of code. I’m currently going through the process of earning my FileNet certification. Just look at this code example from one of the training manuals. This is the “best practice” for passing a query parameter to a search template.

String query = "<executedata xmlns=
 \"http://filenet.com/namespaces/wcm/apps/1.0\">" +
 "<version dtd=\"3.0\"/>" +
 "<objecttypesdata>" +
  "<objecttypedata>" +
   "<from><class symname=\"document\" /></from>" +
    "<templatedata>" +
     "<templatepropitems>" +
      "<templateitem itemid=\"3\">" +
       "<templateitemdata>" + searchValue +
       "</templateitemdata>" +
      "</templateitem>" +
     "</templatepropitems>" +
    "</templatedata>" +
   "</objecttypedata>" +
  "</objecttypesdata>" +

ObjectStore objectStore = ObjectFactory.
StoredSearch ss =
String searchResult = ss.executeXML(query);

Yes, you’re seeing that right. A giant, unnecessary XML query is being painstakingly concatenated together in code, merely to be passed to a Java function in the API that will painstakingly take that XML apart and execute the query. Much execution time is being wasted on both ends of this. XML should not be used in place of proper Remote Procedure Calls. And also notice the overuse of design patterns. This code gets the object store from the object factory, then it gets an object from the object store, all before we are actually able to do anything. Aghhh. It makes my head hurt.

So this is the kind of thing I’ll be dealing with from now on out. I’ve gone from laughing at other people’s misfortunes on Worse Than Failure to solemnly experiencing them firsthand, all in the course of two weeks since beginning the job. Welcome to the wonderful world of IT!

Read the rest of this entry »