Article 4P1FW CodeSOD: Yesterday's Enterprise

CodeSOD: Yesterday's Enterprise

by
Remy Porter
from The Daily WTF on (#4P1FW)

I bumped into a few co-workers (and a few readers- that was a treat!) at Abstractions last week. My old co-workers informed me that the mainframe system, which had been "going away any day now" since about 1999, had finally gone away, as of this year.

A big part of my work at that job had been about running systems in parallel with the mainframe in some fashion, which meant I made a bunch of "datapump" applications which fed data into or pulled data out of the mainframe. Enterprise organizations often don't know what their business processes are: the software which encodes the process is older than most anyone working in the organization, and it must work that way, because that's the process (even though no one knows why).

Robert used to work for a company which offers an "enterprise" product, and since they know that their customers don't actually know what they're doing, this product can run in parallel with their existing systems. Of course, running in parallel means that you need to synchronize with the existing system.

So, for example, there were two systems. One we'll call CQ and one we'll call FP. Let's say FP has the latest data. We need a method which updates CQ based on the state of FP. This is that method.

private boolean updateCQAttrFromFPAttrValue(CQRecordAttribute cqAttr, String cqtype, Attribute fpAttr) throws Exception { AppLogService.debug("Invoking " + this.getClass().getName() + "->updateCSAttrFromFPAttrValue()"); String csAttrName = cqAttr.getName(); String csAttrtype = cqAttr.getAttrType(); String str = avt.getFPAttributeValueAsString(fpAttr); if (str == null) return false; if (csAttrtype.compareTo(CQConstants.CQ_SHORT_STRING_TYPE) != 0 || csAttrtype.compareTo(CQConstants.CQ_MULTILINE_STRING_TYPE) != 0) { String csStrValue = cqAttr.getStringValue(); if (str == null) { return false; } if (csStrValue != null) { if (str.compareTo(csStrValue) == 0) // No need to update. Still // same values { return false; } } cqAttr.setStringValue(str); AppLogService.debug("CQ Attribute Name- " + csAttrName + ", Type- " + csAttrtype + ", Value- " + str); AppLogService.debug("Exiting " + this.getClass().getName() + "->updateCSAttrFromFPAttrValue()"); return true; } if (csAttrtype.compareTo(CQConstants.CQ_SHORT_STRING_TYPE) == 0) { AttributeChoice_type0 choicetype = fpAttr .getAttributeChoice_type0(); if (choicetype.getCheckBox() != null) { boolean val = choicetype.getCheckBox().getValue(); if (val) { str = "1"; } if (str.equals(cqAttr.getStringValue())) { return false; } cqAttr.setStringValue(str); AppLogService.debug("CS Attribute Name- " + csAttrName + ", Type- " + csAttrtype + ", Value- " + str); AppLogService.debug("Exiting " + this.getClass().getName() + "->updateCQAttrFromFPAttrValue()"); return true; } return false; } if (csAttrtype.compareTo(CQConstants.CQ_DATE_TYPE) == 0) { AttributeChoice_type0 choicetype = fpAttr .getAttributeChoice_type0(); if (choicetype.getDate() != null) { Calendar cald = choicetype.getDate().getValue(); if (cald == null) { return false; } else { SimpleDateFormat fmt = new SimpleDateFormat(template .getAdapterdateformat()); cqAttr.setStringValue(fmt.format(cald.getTime())); } AppLogService.debug("CS Attribute Name- " + csAttrName + ", Type- " + csAttrtype + ", Value- " + str); AppLogService.debug("Exiting " + this.getClass().getName() + "->updateCSAttrFromFPAttrValue()"); return true; } return false; } AppLogService.debug("Exiting " + this.getClass().getName() + "->updateCSAttrFromFPAttrValue()"); return false; }

For starters, I have to say that the method name is a thing of beauty: updateCQAttrFromFPAttrValue. It's meaningful if you know the organizational jargon, but utterly opaque to everyone else in the world. Of course, this is the last time the code is clear even to those folks, as the very first line is a log message which outputs the wrong method name: updateCSAttrFromFPAttrValue. After that, all of our cqAttr properties get stuffed into csAttr variables.

And the fifth line: String str = avt.getFPAttributeValueAsString(fpAttr);

avt stands for "attribute value translator", and yes, everything is string-ly typed, because of course it is.

That gets us five lines in, and it's all downhill from there. Judging from all the getCheckBox() calls, we're interacting with UI components directly, pretty much every logging message outputs the wrong method name, except the rare case where it doesn't.

And as ugly and awful as this code is, it's strangely familiar. Oh, I've never seen this particular bit of code before. But I have seen the code my old job wrote to keep the mainframe in sync with the Oracle ERP and the home-grown Access databases and internally developed dashboards and" it all looked pretty much like this.

The code you see here? This is the code that runs the world. This is what gets invoices processed, credit cards billed, inventory shipped, factories staffed, and hazardous materials accounted for.

buildmaster-icon.png [Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today! TheDailyWtf?d=yIl2AUoC8zAQfqg8Fd3hWo
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments