- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Stop Poking Me!
- Operation Erred Successfully
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
frist = comment().count > 0 ? false : true;
Admin
Should be this:
I think that covers it.
Admin
You see, it's very important to distinguish between mobile, not_mobile and FILE_NOT_FOUND.
Admin
The real WTF is calling this ternary abuse. The use of the ternary operator is totally fine here.
Admin
Re NotTheFrist - it is ternary abuse when it is used to set 'true' or 'false' boolean result. No need for ternary then, just simple boolean logic
Admin
not_mobile = (viewport().width > 400) is just fine in many languages.
Admin
else if viewport().width <= 0 throw ViewNotFound
Admin
But what if not_mobile should be FILE_NOT_FOUND ?
Admin
Gah! Another WTF is the name "not_mobile". It should be "desktop" or something that does not include the "not_" prefix. The "not_" prefix leads to bug-prone code like "If (not_mobile == FALSE) { /* mobile code / } else { / desktop code */ }". It's awful.
Admin
Yep. Use the positive sense, not the negative sense. See also:
https://devblogs.microsoft.com/oldnewthing/20070314-00/?p=27623
https://devblogs.microsoft.com/oldnewthing/20080624-00/?p=21863
Admin
Always happy to learn from a master.
Admin
At least JavaScript supports ternary operators. For instance in Python the same code would be:
not_mobile = True if viewport.width() > 400 else False
Admin
Ah, if that is what the author meant with abuse, then he is of course correct. I would also have written it like Hasseman. I was under the assumption that the author meant that one should have written it with if and else instead of with the ternary operator. Seems like I was mistaken.
Admin
Of course, with missing parens to clarify matters, the author could have meant to compare the width with
true
orfalse
, depending on the truth value of 400...not_mobile = viewport().width > (400 ? true : false);
Admin
@Raj: "At least JavaScript supports ternary operators. For instance in Python the same code would be:
not_mobile = True if viewport.width() > 400 else False"
Come on, don't do the same thing in Python. This is enough:
not_mobile = viewport.width() > 400 # right-hand side is already a boolean
or avoiding the negative name (better):
is_mobile = viewport.width() <= 400
Admin
Perhaps simply "mobile" i.e.
mobile = viewport().width <= 400
Admin
viewport().width = 400 ? Hmmm
Admin
I, for one, would prefer sites go to a non-mobile design when my phone is in landscape mode.
Admin
A reasonable Python version would be:
not_mobile = viewport().width > 400
Or, better...
mobile = viewport().width <= 400
Admin
if (frist != false) not_frist = frist ? frist : false; else not_frist = false;
Admin
If you wanted to write perl in python, yes.
Admin
Yeah, for future expandability, this should be a switch statement with approx. 1024 cases, generating an enum value, accompanied by a code generator to create it.
(ETA: I have apparently become a robot. reCaptcha accepted my idea of palm trees on the first try. That's how these tests work, isn't it?)
Admin
I've done that for a bit of mine. Tables appear in full form in landscape, but as a list in portrait. My favourite part is a link that says "Period Table" in landscape, and "List of Elements" in portrait, so as long as the viewport width doesn't change while it's loading, it's consistent.
Admin
Well, on the other hand, there are still many web sites out there which assume that I use the total width of my 3 monitors for viewing them ...
Admin
Without seeing the rest of the code I can guess why it's called "not_mobile". Somewhere this would have been added to an existing system - perhaps a purely DeskTop system - and as the default value for "not_mobile" would be "false" its the route of least breaking changes with minimum effort. Certainly not an excuse but it is a reasonable reason.
Admin
I despise code that makes assumptions about being mobile based on the window size. I generally open my web browser on a 1080p display in portrait orientation, and find way too many web sites assume I'm on a mobile device because the browser window, when maximized, is "only" 1080 pixels wide, and is even smaller when it's not maximized.
Furthermore, all these sites assume you keep your browser window maximized. I almost never do, and tons of sites switch to their mobile view if I don't make the window more than half the width of the screen. Maybe I'm the only person left on the Internet who likes to see multiple partially-overlapping windows on a desktop, but this is really annoying.
If you can't figure out a reliable way to determine if the device is mobile (can you just check to see if the browser's OS is iOS or Android?) then don't do it at all. Making assumptions based on the size of a browser window is just wrong.
Admin
This code looks like it was written in a rush for a system with, let's just say, a long history, IYKWIM...
Admin
Good luck in your campaign against Responsive Web Design (at least the way any CSS framework I've seen seems to implement it).