Subscribe: The Daily WTF
Preview: The Daily WTF

The Daily WTF

Curious Perversions in Information Technology

Last Build Date: Tue, 26 Sep 2017 02:20:59 GMT


CodeSOD: The Strangelet Solution

Mon, 25 Sep 2017 10:30:00 GMT

Chris M works for a “solutions provider”. Mostly, this means taking an off-the-shelf product from Microsoft or Oracle or SAP and customizing it to fit a client’s specific needs. Since many of these clients have in-house developers, the handover usually involves training those developers up on the care and maintenance of the system. Then, a year or two later, the client comes back, complaining about the system. “It’s broken,” or “performance is terrible,” or “we need a new feature”. Chris then goes back out to their office, and starts taking a look at what has happened to the code in his absence. It’s things like this: var getAdjustType = Xbp.Page.getAttribute("cw_adjustmenttype").getText; var reasonCodeControl = Xbp.Page.getControl("cw_reasoncode"); if (getAdjustType === "Short-pay/Applying Credit" || getAdjustType === "Refund/Return (Credit)") { var i; var options = (Xbp.Page.getAttribute("cw_reasoncode").getOptions()); reasonCodeControl for (i = 0; i < options.length; i++) { if (i <= 4) { reasonCodeControl.removeOption(options[i].value); } if (i >= 5) { reasonCodeControl.clearOptions(); } if (i >= 5) { reasonCodeControl.addOption(options[5]); reasonCodeControl.addOption(options[6]); reasonCodeControl.addOption(options[7]); reasonCodeControl.addOption(options[8]); reasonCodeControl.addOption(options[9]); reasonCodeControl.addOption(options[10]); reasonCodeControl.addOption(options[11]); reasonCodeControl.addOption(options[12]); reasonCodeControl.addOption(options[13]); reasonCodeControl.addOption(options[14]); reasonCodeControl.addOption(options[15]); reasonCodeControl.addOption(options[16]); reasonCodeControl.addOption(options[17]); reasonCodeControl.addOption(options[18]); reasonCodeControl.addOption(options[19]); reasonCodeControl.addOption(options[20]); reasonCodeControl.addOption(options[21]); } } } else { var options = (Xbp.Page.getAttribute("cw_reasoncode").getOptions()); for (var i = 0; i < options.length; i++) { if (i >= 4) { reasonCodeControl.removeOption(options[i].value); } if (i <= 4) { reasonCodeControl.clearOptions(); } if (i <= 4) { reasonCodeControl.addOption(options[0]); reasonCodeControl.addOption(options[1]); reasonCodeControl.addOption(options[2]); reasonCodeControl.addOption(options[3]); reasonCodeControl.addOption(options[4]); } } } There are patterns and there are anti-patterns, like there is matter and anti-matter. An anti-pattern would be the “switch loop”, where you have different conditional branches that execute depending on how many times the loop has run. And then there’s this, which is superficially similar to the “switch loop” anti-pattern, but confused [Advertisement] Incrementally adopt DevOps best practices with BuildMaster, ProGet and Otter, creating a robust, secure, scalable, and reliable DevOps toolchain. [...]