- Feature Articles
- CodeSOD
- Error'd
- 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
WoW, JavaScript and PHP hand in hand without php tags :/
Ooh, and frist
Admin
Who doesnt like to prty of it?
Admin
I've been a party to fava beans.
Admin
A botched special-case botch - classic. :-)
Admin
Code like this is why PHP developers are seen as the GoBots of the development world.
Admin
"it games from x"
WTF kind of abuse of the English language is this? Just a guess, but maybe it was outsourced to India?
And if you truly aspire to create else-free code, I recommend you study up on De Morgan's Laws first.
Admin
It games from there because unless you play it you don't win that result.
Admin
It games from there because unless you play it you don't win that result.
Admin
Captcha: acsi; "-I tried to find my sysAdmin because my ACSI is acting up, but he's always unreachable.
Admin
What's the problem here? Sure, code looks ugly, but ifs are so fast to compute, even in php that elses aren't really needed. Moreover, in some cases adding else may even increase execution time by several milliseconds.
Admin
Admin
You know, I looked at this code, and I don't see anything that's in need of elses. What I see is lots of redundant conditions - a series of "if some-condition and logged-in then echo some-gobble" instead of a series of "if some-condition then echo some-gobble" inside the brace block of "if logged-in then { ... }".
There's also a bunch of explicit comparisons to 'true' (the string!), which has overpowering code smell.
So once again, it's a WTF, but it isn't the WTF that the editor thinks it is, although Bruce is right that the comments aren't particularly useful.
Admin
Admin
It games from lotion.php or it gets the hose again.
Admin
Admin
"Best football results twice again."
Admin
TRWTF is that this code would do nothing but throw a javascript syntax error, since (as was pointed out) the php statements aren't wrapped in open/closing tags.
Admin
I don't know about "GoBots," but...
Which do we deem scarier? That he doesn't seem to know the difference between server and client side? Or that he doesn't seem to know the difference between Javascript/JQuery and PHP?
Admin
The problem with code like this is that it hides unintended side effects. For one the if's are now order dependent. That's why elses are needed -- they make the dependency more obvious. And, code like this always starts out as 2 or 3 ifs followed by 35 or 40 eventual additions over time.
Admin
Use of ResSharper in action.
Admin
If that is even true, perhaps you are using the wrong language and the trwtf is php! :P
Admin
TRWTF is PHP... mixed with JavaScript.
I've seen some pretty WTF-ey PHP and some pretty WTF-ey JS, but never have I seen a mix of the two.
Presumably who discovered this was wondering why a webpage wasn't working, and viewed source...
Admin
Exactly.
Whoever did this either was unaware of the distinction between client-side and server-side; or PHP and Javascript/JQuery; or both.
The code is like a Stack Overflow word-salad, obtained and assembled from Google search. By Elmer Fudd, or maybe Mr. Magoo.
Admin
I'd say that whoever did this has never attended CS.101
Admin
Good code doesn't need to look nice. Good code needs to work nice. Frankly, code like that means job security for whoever wrote it originally so there's another plus (even if they fire him, they'll quickly rehire him as no one could understand it).
Admin
Your statement that ifs are "fast" makes no sense, because an "if" is not a distinct built-in operation; it depends entirely on the evaluation of the condition.
Good code DOES need to look nice. Code goodness is measured first by how easily read and well understood by humans it is -- that is the very purpose of programming languages. Goodness is then measured second by how easily it can be modified by humans and how adaptable to change the structure and algorithms are.
This code fails on both of these foremost concerns. It fails at readability, obviously. And it fails at resilience because we are counting on the fact that only one branch is executed, which could change in the future and break it, because the else-logic is implied and not enforced.
Saving milliseconds of execution speed doesn't excuse this and make it "good" code. Furthermore, if your compiler actually DOES produce slower code from a source algorithm that has less steps (if-else), this also does not mean the faster code is "good" -- it means that neither the code nor the hideously broken compiler are good.
Job security is not a "plus" here, it's irrelevant. You asked "what's the problem here" and got the answer. The fact that there is job security does not negate the fact that there is a problem.
Admin
I've seen it, even done it. Usually only to the extent of echoing a variable into the script, but there are PHP libraries to generate various JS UI scripts. Writing JS entirely with PHP tends to be pretty ugly and pointless, but in limited amounts it's not too bad. Using PHP to concatenate JS is also fairly common.
I shouldn't need to point out that View Source would not have shown the PHP code unless the server was misconfigured.
Admin
Psst... I think he might be trolling.
Admin
Not likely. The attempts at further strengthening his point would have only served to detract from the trolling. Misconceptions like "else increases execution time" and shortsightedness like "optimization is better than readability" are far too common for that to be a foregone conclusion.
Admin
For a moment I've enjoyed a sweet idea, that he sent $_SESSION and $_POST arrays down the wire to JS variables with the same names! But then the illusion vanished, when I've noticed "->" operator which does not even parse in JS.