Subscribe: The Daily WTF
http://syndication.thedailywtf.com/TheDailyWtf
Preview: The Daily WTF

The Daily WTF



Curious Perversions in Information Technology



Last Build Date: Sat, 24 Feb 2018 14:54:41 GMT

 



Error'd: Everybody's Invited!

Fri, 23 Feb 2018 11:30:00 GMT

"According to Outlook, it seems that I accidentally invited all of the EU and US citizens combined," writes Wouter.

(image)

 

"Just an array a month sounds like a pretty good deal to me! And I do happen to have some arrays to spare..." writes Rutger W.

(image)

 

Lucas wrote, "VMWare is on the cutting edge! They can support TWICE as much Windows 10 as their competitors!"

(image)

 

"I just wish it was CurrentMonthName so that I could take advantage of the savings!" Ken wrote.

(image)

 

Mark B. "I had no idea that Redboxes were so cultured."

(image)

 

"I'm a little uncomfortable about being connected to an undefined undefined," writes Joel B.

(image)

 

(image) [Advertisement] Easily create complex server configurations and orchestrations using both the intuitive, drag-and-drop editor and the text/script editor.  Find out more and download today!
(image)



CodeSOD: Functional IsFunction

Thu, 22 Feb 2018 11:30:00 GMT

Julio S recently had to attempt to graft a third-party document viewer onto an internal web app. The document viewer was from a company which specialized in enterprise “document solutions”, which can be purchased for enterprise-sized licensing fees.

Gluing the document viewer onto their internal app didn’t go terribly well. While debugging, and browsing through the vendor’s javascript, he saw a lot of calls to a function called IsFunction. It was loaded from a “utilities”-type do-everything library file. Curious, Julio pulled up the implementation.

function IsFunction ( func ) {
    var bChk=false;
    if (func != "undefined") bChk=true;
    else bChk=false;
    return bChk;
}

I cannot emphasize enough how beautiful this block of code is, by the standards of bad code. There’s so much there. One variable, bChk uses Hungarian notation. Nothing else seems to. It’s a totally superfluous variable, as we could just do return func != "undefined".

Then again why would we even do that? The real beauty, though, is how the name of the function and its implementation have no relationship to each other, and the implementation is utterly useless. For example:

IsFunction("Hello World"); //true
IsFunction({spam: "eggs"}); //true
IsFunction(function() {}); //true, but it was probably an accident
IsFunction(undefined); //true
IsFunction("undefined"); //false

Yes, the only time this function returns false is the specific case where you pass it the string “undefined”. Everything else IsFunction apparently. The useless function sounds important. Someone wrote it, probably as a quick attempt at vaguely defensive programming. “I should make sure my inputs are valid”. They didn’t test it. The certainly didn’t think about it. But they wrote it. And then someone else saw the function in use, and said, “Oh… I should probably use that, too.” Somewhere, there’s probably a “Style Guide”, which mandates that, before attempting to invoke a variable that should contain a function, you use IsFunction to confirm it does. It comes up in code reviews

(image) [Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!
(image)