Article 3B3Q Coded Smorgasbord: Efficient WTFery

Coded Smorgasbord: Efficient WTFery

by
Remy Porter
from The Daily WTF on (#3B3Q)

Some horrible code is acres of awful, thousands of tortured lines of mess and horror. Some developers can compress their WTFs down into a handful of lines.

For example, Zlatko was working with a Node.js developer who was big on unit tests. Unfortunately, that developer didn't understand that you couldn't write a synchronous test for an asynchronous method- the test will always pass.

That's why this code, buried in a callback, passed:

while (i <= location.length) { if (i === location[i - 1].rank) { i++; }};

Or take Wendy, who inherited an application that has to deal with poorly sanitized data. Some fields, like Print_Code, are VARCHAR(2), which means many records end up with a trailing space.

Wendy's co-worker cleaned out that extra white-space with this block:

String print_code = " ".concat(dto.getPrint_code().trim());if (print_code.length() == 3) {print_code = print_code.trim();}

With Java web development, it's not uncommon to need to detect whether you're inside of WebLogic, Tomcat, etc.. Josh found this" exceptional solution in his codebase:

boolean isTomcat = new Throwable().getStackTrace()[1].toString().indexOf("org.apache.catalina") > -1;

For a language not exactly known for its brevity, this amount of WTF in a single line is quite an achievement.

Then again, maybe we don't need a line of code at all. Alexandre was hunting a bug that caused the wrong products to show up as a "deal" in their e-commerce site. Fortunately, his predecessor documented the code quite well:

/* ATTENTION: this crap below is messed up and brings more deals than you expect, it is because SQL SP looks up for the deals inside children groups of selected group. Don't change this until somebody notice the situation */

And finally, we'll close with a true confession from Corey. When Corey started a comp-sci program in college, he aleady had a fair bit of experience as a developer. When his professor assigned a "write a factorial function" exercise, Corey turned in this:

int f(int n){return n?f(n-!!n)*n:!n;}

The professor was not amused.

release50.png[Advertisement] Release!is a light card game about software and the people who make it. Order the massive, 338-card Kickstarter Edition (which includes The Daily Wtf Anti-patterns expansion) for only $29.95, shipped! TheDailyWtf?d=yIl2AUoC8zAh0FuFXMWBhk
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