CodeSOD: Holiday Sample Pack

Today, let's whip up a holiday sampler of some short snippets. We start with this anonymously supplied ternary, which certainly terned my head:

return (accounts == 1 ? 1 : accounts)

If accounts equals 1, return 1, otherwise return accounts. Perfect.

On the other hand, submitter Born 2 Ruby, Forced 2 PHP was hired to work on a Ruby on Rails application, but after starting, discovered that the RoR app was an aspiration and the day to day work was to keep the legacy PHP application from falling over in production. So as it turns out, this submitter should have said "no", when they said "yes", much like this code:

function yesorno($in) { if($in == 'YES') return 'YES'; else return 'NO'; }

And finally, another anonymous submitter sent us this comment they wrote in their code, which I think speaks both for themselves and for anyone who even inherits that code.

// i should have commented this stupid code
[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published. Required fields are marked *