We all just love ternaries around here. So much. A powerful form of code golf, they can clarify and they can confound, but usually it’s just confounding.

Christopher sends us this example, saying, “This is an accurate indicator of the rest of the code.”

not_mobile = viewport().width > 400 ? true : false;

Representative indeed, and there’s a lot packed into this beyond the ternary abuse. First off, our standard for being not_mobile, which I assume is “not a mobile device” for displaying this site, is a screen that’s 400 pixels wide. Which is fine, until someone turns their 2007 iPhone into landscape mode, which is 480px wide. I assume this site has a banner “Best Viewed using a Palm Pilot”.

Of course, the root WTF is trying to set responsive breakpoints in JavaScript, when CSS has a rich set of features to handle that. Then again, they’re apparently using a custom viewport object, which implies that perhaps the viewport element wasn’t fully supported when they wrote it, so maybe it’s just an old site?

Which brings us back around to the ternary abuse. Maybe the code is just plain bad.

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!