Article 6MY2Y CodeSOD: Delectable Code

CodeSOD: Delectable Code

by
Remy Porter
from The Daily WTF on (#6MY2Y)

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(){ //This delects everything from the table minus 3 days $thedel = $this->db->query('Delete FROM ClientReportsRelationship where DateEntered <= (CURRENT_DATE - Interval 31 DAY) '); //$thedel2 = $this->db->query('Delete FROM ClientReportsRelationship where CustomerId = 33 ');}

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.

proget-icon.png [Advertisement] ProGet's got you covered with security and access controls on your NuGet feeds. Learn more.
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