Article 3DATZ Representative Line: Tern Back

Representative Line: Tern Back

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

In the process of resolving a ticket, Pedro C found this representative line, which has nothing to do with the bug he was fixing, but was just something he couldn't leave un-fixed:

$categories = (isset($categoryMap[$product['department']]) ? (isset($categoryMap[$product['department']][$product['classification']]) ? $categoryMap[$product['department']][$product['classification']] : NULL) : NULL);

Yes, the venerable ternary expression, used once again to obfuscate and confuse.

It took Pedro a few readings before he even understood what it did, and then it took him a few more readings to wonder about why anyone would solve the problem this way. Then, he fixed it.

$department = $product['department'];$classification = $product['classification'];$categories = NULL;//ED: isset never triggers as error with an undefined expression, but simply returns false, because PHPif( isset($categoryMap[$department][$classification]) ) { $categories = $categoryMap[$department][$classification];}

He submitted the change for code-review, but it was kicked back. You see, Pedro had fixed the bug, which had a ticket associated with it. There were to be no code changes without a ticket from a business user, and since this change wasn't strictly related to the bug, he couldn't submit this change.

atlasoft-50x50.png [Advertisement] Atalasoft's imaging SDKs come with APIs & pre-built controls for web viewing, browser scanning, annotating, & OCR/barcode capture. Try it for 30 days with included support. TheDailyWtf?d=yIl2AUoC8zAjmcu9TjwqSA
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