• LostDreamer (unregistered)

    WoW, JavaScript and PHP hand in hand without php tags :/

    Ooh, and frist

  • partyJoe (unregistered)

    Who doesnt like to prty of it?

  • Hannes (unregistered)

    I've been a party to fava beans.

  • (cs)

    A botched special-case botch - classic. :-)

  • Thegoryone (unregistered)

    Code like this is why PHP developers are seen as the GoBots of the development world.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    "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.

  • Rfoxmich (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL

    It games from there because unless you play it you don't win that result.

    ¯\(°_o)/¯ I DUNNO LOL:
    "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.

  • Rfoxmich (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL

    It games from there because unless you play it you don't win that result.

    ¯\(°_o)/¯ I DUNNO LOL:
    "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.

  • ZoomST (unregistered) in reply to Rfoxmich
    Rfoxmich:
    It games from there because unless you play it you don't win that result.
    ¯\(°_o)/¯ I DUNNO LOL:
    "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.

    Ah, IT games are such entertaining, like "find the hidden network admin", "hack the company web"...

    Captcha: acsi; "-I tried to find my sysAdmin because my ACSI is acting up, but he's always unreachable.

    • What's an ACSI.
    • I don't know, I'm not a sysAdmin.
    • Have you tried turning it off and on again?"
  • Tux "Tuxedo" Penguin (unregistered)

    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.

  • mara (unregistered) in reply to Tux "Tuxedo" Penguin
    Tux "Tuxedo" Penguin:
    What's the problem here? Sure, code looks ugly
    Asked and answered.
  • (cs)

    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.

  • (cs) in reply to ¯\(°_o)/¯ I DUNNO LOL
    ¯\(°_o)/¯ I DUNNO LOL:
    "it games from x"

    WTF kind of abuse of the English language is this? Just a guess, but maybe it was outsourced to India?

    "It was not came's. He borrowed mine."
  • cyborg (unregistered)

    It games from lotion.php or it gets the hose again.

  • Paul Neumann (unregistered) in reply to cyborg
    cyborg:
    It games from lotion.php or it gets the hose again.
    No 'else'? I see what you did there.
  • Dave (unregistered) in reply to Quietust

    "Best football results twice again."

  • tag stripper (unregistered)

    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.

  • (cs) in reply to Thegoryone
    Thegoryone:
    Code like this is why PHP developers are seen as the GoBots of the development world.

    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?

  • Consensual Commenter (unregistered)

    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.

  • Fake' Nagesh (unregistered)

    Use of ResSharper in action.

  • Butthats 4Eva (unregistered) in reply to Tux "Tuxedo" Penguin
    Tux "Tuxedo" Penguin:
    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.

    If that is even true, perhaps you are using the wrong language and the trwtf is php! :P

  • Trolinov Fairezhky (unregistered)

    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...

  • (cs) in reply to Trolinov Fairezhky
    Trolinov Fairezhky:
    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...

    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.

  • Pista (unregistered) in reply to Coyne
    Coyne:

    Whoever did this either was unaware of the distinction between client-side and server-side; or PHP and Javascript/JQuery; or both.

    I'd say that whoever did this has never attended CS.101

  • Tux "Tuxedo" Penguin (unregistered) in reply to mara
    mara:
    Tux "Tuxedo" Penguin:
    What's the problem here? Sure, code looks ugly
    Asked and answered.

    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).

  • nmclean (unregistered) in reply to Tux "Tuxedo" Penguin
    Tux "Tuxedo" Penguin:
    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.
    Tux "Tuxedo" Penguin:
    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).
    Hogwash.
    1. 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.

    2. 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.

    1. 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.

    2. 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.

  • Guilty PHP Dev (unregistered) in reply to Trolinov Fairezhky

    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.

  • cyborg (unregistered) in reply to nmclean
    nmclean:
    Tux "Tuxedo" Penguin:
    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.
    Tux "Tuxedo" Penguin:
    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).
    Hogwash.
    1. 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.

    2. 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.

    1. 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.

    2. 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.

    Psst... I think he might be trolling.

  • nmclean (unregistered) in reply to cyborg
    cyborg:
    Psst... I think he might be trolling.

    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.

  • qbolec (unregistered)

    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.

Leave a comment on “We Don't Need no Stinking Elses”

Log In or post as a guest

Replying to comment #:

« Return to Article