Saturday, June 15, 2024

Delectable Code – The Daily WTF

Programming LanguageDelectable Code - The Daily WTF


Good method names are one of the primary ways to write self-documenting code. The challenge there, is that documentation often becomes out of date.

Take this delectable PHP nugget, from Nathaniel P, who has previously been tortured by bad date handling.

function deleteTenDays()
{
        
        $thedel = $this->db->query('Delete FROM ClientReportsRelationship where DateEntered <= (CURRENT_DATE - Interval 31 DAY) ');
        
}

The function is called deleteTenDays. The comment tells us that it “delects everything” from the table “minus 3 days”. The actual delete query deletes everything older than a month. For bonus points, there’s a commented out query which just deletes everything from a single customer.

Honestly, this function needs to be delected.

[Advertisement]
ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

Check out our other content

Check out other tags:

Most Popular Articles