Recent Articles

24 Oct 2014

Undefined Favorites

by Mark Bowytz in Error'd on 2014-10-24

"It's great I can ship my favorites to Europe, I just wish I knew what they were," writes Nick.

38 Comments - Last Comment @ 14:11
23 Oct 2014

The Beginning of the Zend

by Remy Porter in CodeSOD on 2014-10-23

Karol found a program that needs to look at a timestamp, and determine if that timestamp is before or after an expiration date. The code that was handling this looked like this:

public function _isSmsCodeExpired($id)
    {

        $genDateStr = $this->db()->query('SELECT date FROM table')->fetchColumn();

        if (empty($genDateStr))
        {
            return true;
        }
        
        $expireDateArr = array();
        $intervalSec = 120;

        $genDataTmp = explode(' ', $genDateStr);
        $genDataArr = explode('-', $genDataTmp[0]);

        $expireDateArr['year'] = $genDataArr[0];
        $expireDateArr['month'] = $genDataArr[1];
        $expireDateArr['day'] = $genDataArr[2];

        $genDataArr = explode(':', $genDataTmp[1]);

        $expireDateArr['hour'] = $genDataArr[0];
        $expireDateArr['minute'] = $genDataArr[1];
        $expireDateArr['second'] = substr($genDataArr[2], 0, 2);

        $intervalMin = (int) $intervalSec / 60;
        $intervalSec = (int) $intervalSec - ( $intervalMin * 60 );

        $expireDateArr['second'] += $intervalSec;
        $expireDateArr['minute'] += $intervalMin;

        $expireDateArr['second'] += $intervalSec;
        if ($expireDateArr['second'] > 60)
        {
            $expireDateArr['minute'] += 1;
            $expireDateArr['second'] = $expireDateArr['second'] - 60;
        }

        if ($expireDateArr['minute'] > 60)
        {
            $expireDateArr['hour'] += 1;
            $expireDateArr['minute'] = $expireDateArr['minute'] - 60;
        }

        if ($expireDateArr['hour'] > 24)
        {
            $expireDateArr['day'] += 1;
            $expireDateArr['hour'] = $expireDateArr['hour'] - 24;
        }

        $daysInMonth = date("t", strtotime($expireDateArr['year'] . "-" . $expireDateArr['month'] . "-01"));

        if ($expireDateArr['day'] > $daysInMonth)
        {
            $expireDateArr['month'] += 1;
            $expireDateArr['day'] = $expireDateArr['day'] - $daysInMonth;
        }

        if ($expireDateArr['month'] > 12)
        {
            $expireDateArr['year'] += 1;
        }


        $expireDate = new Zend_Date($expireDateArr);
        $now = new Zend_Date();

        if ($now->isEarlier($expireDate))
            return false;
        else
            return true;
    }

56 Comments - Last Comment @ 14:00
22 Oct 2014
21 Oct 2014

Tokyo Meet-up & Site Fixes

by Alex Papadimoulis in Announcements on 2014-10-21

Tokyo readers -- I am once again visiting your fine city this week, and thought it'd be fun to try for another Tokyo/TDWTF meetup. Earlier this year, we got together at an izakaya for nomihoudai:

13 Comments - Last Comment @ 2014-10-22
21 Oct 2014

Is It Safer to Use Numbers?

by Mark Bowytz in CodeSOD on 2014-10-21

Mac didn't know anything about how the JavaScript on the search page worked, and he wasn't that great at CSS styling, but that didn't matter. He had his orders. As part of the latest round of enhancements, the front-end developer had added another search parameter which would be passed via the regular search URL, and the back end needed to be adjusted to accomodate. (You know... instead of 'http://initrode.com/search?a=xxx&b=yyy' it now was 'http://initrode.com/search?a=xxx&b=yyy&c=zzz'.)

No problem. Mac made his tweak in the code and ran a quick test...which failed instantly in a spectacular way. "WTF? It's a parameter. Must be already used..." he thought, but nope.

17 Comments - Last Comment @ 2014-10-23
20 Oct 2014

Parallel SQL Queries

by snoofle in CodeSOD on 2014-10-20

Daniele worked at a pharmaceutical firm that had an old web application that allowed commercial customers to look up information. Since the data was quite complicated, there were numerous fields that needed to be queried in order to populate the form.

Unfortunately, as the amount of data in the system grew, the time to load the form grew as well. And grew. And grew.

75 Comments - Last Comment @ 11:29
17 Oct 2014

The New Look is Here

by Alex Papadimoulis in Announcements on 2014-10-17

As you may have noticed, the site looks quite a bit different! As I mentioned back in March, it's been almost seven years since the look and feel of The Daily WTF has been updated, and I was getting pretty tired of the "2003ish" vibe the site had.

You guys gave some fantastic feedback to help guide the new design, and in July I shared a preview look. After some more feedback - both on the GitHub issue tracker and the forums - we put on the finishing touches and launched the site this evening.

174 Comments - Last Comment @ 06:59
17 Oct 2014

Sorry, but You Can't Do the Math

by Mark Bowytz in Error'd on 2014-10-17

"I guess that Intuit might have reasons for not allowing me to say Math was my least favorite subject in school," writes Alan R.

58 Comments - Last Comment @ 2014-10-21
16 Oct 2014
15 Oct 2014

Line by Line

by Remy Porter in CodeSOD on 2014-10-15

In the bowels of a business unit, a director got a great deal on a third party software package. He bought it, without talking to corporate IT, and then was upset when it couldn’t gracefully integrate with any of the corporate IT assets. Eager to throw good money after bad, the director hired his nephew’s consultancy to build an integration tool to make his new toy work.

A few months later, the users complained about performance, and somehow, fixing this thing became Jeff’s problem. The process was simple enough: slurp enterprise data out of a text file, and pass the data on to the third-party tool. It didn’t take Jeff long to figure out why it performed poorly:

55 Comments - Last Comment @ 14:14
14 Oct 2014
13 Oct 2014

We Don't Need no Stinking Elses

by Bruce Johnson in CodeSOD on 2014-10-13

We've all seen it before. I dare say we've all been a party to it.

First, we look at a block of code that needs to be modified. Then we determine which criteria needs to be added to address the case that we've been tasked to implement. Next, we add the condition and walk away before the waft from the code smell reaches our nostrils. Over time, a monstrosity like the following arises from the depths. Not something that couldn't be greatly improved by some fava beans and a nice refactor. I'm sure the unit tests that cover your production code base will ensure that your refactoring was successful. Right? Right??

30 Comments - Last Comment @ 14:14
10 Oct 2014

Do the Math

by Mark Bowytz in Error'd on 2014-10-10

"These car shades I found at Walmart were made especially for the American market," Bryan W. writes, "I mean just look - they work much better in Fahrenheit than in Celsius."

71 Comments - Last Comment @ 2014-10-16
09 Oct 2014

IP Address Denial

by Mark Bowytz in CodeSOD on 2014-10-09

While trying to assign an address from his framed /29 route to the internal side of his Linksys AM300 router, Phillip S. received an unexpected "Local IP Address is not valid" error.

Being a web script error, Phillip correctly figured that he could dig into what condition would make the address come up as invalid. Turns out, his problem was that the router considers any IP address starting with 115 to be invalid, but Phillip found that there were a few other instances of hard coding and magic number abuse. On a positive note, at least it's not device-side code.

43 Comments - Last Comment @ 2014-10-15
08 Oct 2014
07 Oct 2014

Enterprise GUID

by Remy Porter in CodeSOD on 2014-10-07

Jonathon recently got a new co-worker who is an enterprise systems developer, with an emphasis on enterprise. For an enterprise-level WTF, today’s code is short, but it packs itself up with everything it could do wrong.

using System;

namespace Business.Common.Services
{
    /// <summary>
    /// Guid service.
    /// </summary>
    public class GuidService : IGuidService
    {
        /// <summary>
        /// Initializes a new instance of the System.Guid structure.
        /// </summary>
        /// <returns>A new GUID object.</returns>
        public Guid NewGuid()
        {
            return Guid.NewGuid();
        }
    }
}

72 Comments - Last Comment @ 2014-10-19
06 Oct 2014
03 Oct 2014

The Post Office is Wrong

by Mark Bowytz in Error'd on 2014-10-03

Mark H. wrote, "Despite being a company that specializes in shipping orders, I guess Tiger Direct has no idea which zip codes are in which cities."

49 Comments - Last Comment @ 2014-10-07
02 Oct 2014

Ternary Operator Nesting Syndrome

by Mark Bowytz in Representative Line on 2014-10-02

Back in July, I wrote about my disdain for ternary operators citing a monster representative line as being a great example of an attempt at cleverness gone too far.

Well, an anonymous submitter sent our way another ternary operator disaster but with a twist - nested within the call to "payRecordsList.Add", almost every parameter passed has its own ternary operator added.

40 Comments - Last Comment @ 2014-10-07
01 Oct 2014