• Anom (unregistered)

    for(;;) {

    echo "Am I frist?";

    }

  • Pacifisto (unregistered)

    Haven't the last two come up before? I feel like the last one especially was almost word-for-word posted some time ago ($cat instead of $category).

  • Honnza (unregistered)
    if (dncrptList.Contains(destName))
    {
       dId = SymmetricMethod.Decrypto(id);
    }
    else
    {
       dId = SymmetricMethod.Decrypto(id);
    }
    

    isn't a WTF. It happens when the logic changes frequently. Rather than merge the two branches and then try to remember what the condition was when the logic requests diverging pathways, you simply leave an if statement stub that you can expect later.

    Coding to specification is like walking on water. It's easier when it's frozen.

  • Frank (unregistered)
    for (;;) {
    I think there's a new emoticon in there somewhere for that sick feeling you get when the fog of code smell lifts to reveal an actual rotting corpse.
  • Eve (unregistered)

    Adam, the most important thing about an if statement is to get the braces on separate lines. I think your cow orker has learned that lesson admirably.

  • (cs)

    The first snippet would be fixed by using

    while(true)
    instead of
    for(;;)
    and properly closing the input tag.

    Addendum (2013-02-28 08:09): Also, the name fits the dog better.

  • foo (unregistered) in reply to Anom
    Anom:
    for(;;) {
    10:
       echo "Am I frist?";
       goto 10;
    }
    FTFY.
  • (cs) in reply to portablejim
    portablejim:
    The first snippet would be fixed by using
    while(true)
    instead of
    for(;;)
    and properly closing the input tag.
    Thank goodness the break tag was properly closed.
  • Steve (unregistered) in reply to Honnza

    Or, y'know, you could let version control do its job and not leave redundant code all over the place.

  • Anonymous Paranoiac (unregistered) in reply to Frank
    Frank:
    for (;;) {
    I think there's a new emoticon in there somewhere for that sick feeling you get when the fog of code smell lifts to reveal an actual rotting corpse.
    Sometimes the code wins
    foo:
    Anom:
    for(;;) {
    10:
       echo "Am I frist?";
       goto 10;
    }
    FTFY.

    The more ancient segments of the code base at work are littered with things like:

    while (foo) {
      if (bad_condition) goto 99
      *snip*
      99:
      continue
    }
    

    Of course, the language it's written in doesn't actually support while loops (well, not as while loops). Or curly braces.

    Occasionally, you'll even see:

    10:
    if (loop_condition) {
      *snip*
      goto 10
    }
    

    We obviously kill these things on sight.

  • VS (unregistered) in reply to Anom

    This is not a WTF!

    Long time ago, before the while loop existed, this was the available loop with scope.

    for(;;) { // do stuff if (something) break; }

  • Virus? (unregistered)

    Someo I work with managed to figure out how to use reflection in Java to do a for loop.

  • Euripides (unregistered)

    Reminds me of code my former boss wrote (in PL/SQL):

    for rec in cur loop <<lbl>> if (condition) goto lbl; ... end;

    And then she complained that the database was too slow.

  • Drake (unregistered) in reply to Frank
    Frank:
    for (;;) {
    I think there's a new emoticon in there somewhere for that sick feeling you get when the fog of code smell lifts to reveal an actual rotting corpse.

    New emoticon? Why not Zoidberg?

    (;;) {

  • (cs)

    Not a well-respected or especially feared super-villain, though. Pretty much limited to arching Encrypto and nobody knows what the hell that guy's talking about anyway.

    (And how much do you love "Venture Brothers" for giving us this use of the word arching?)

  • Sanhadrin (unregistered) in reply to VS
    VS:
    This is not a WTF!

    Long time ago, before the while loop existed, this was the available loop with scope.

    for(;;) { // do stuff if (something) break; }

    Er, except, that's not what he's doing. Rather than putting the increment and terminating conditions of a counter in the for statement, he put it in the body, as if he was trying to implement a for loop in a while statement.

    But, obviously you knew something so incredibly basic, and I'm obviously getting trolled. That's the preferable reality here.

  • Pock Suppet (unregistered) in reply to Eve
    Eve:
    Adam, the most important thing about an if statement is to get the braces on separate lines.
    Heresy! True programmers only use single-line, braceless block constructs. Preferably heavily nested:
    if ( foo )
       while ( vmixingCase_Styles )
          if ( some || any )
          for ( blargh in blargher )
             if ( !blargh )
                thisVar = "1"
                if ( thisVar == "1" )
                   doGoValidate_Blargh( blargh )
    
    This example serves to clearly demonstrate the superiority of braceless block constructs. (To our great regret, the !blargh block was unable to utilize this superior technique appropriately. Perhaps the programmer was unfamiliar with the "if ( thisVar = "1" && thisVar == "1" )" pattern. Alas.) It also demonstrates many excellent ways to irritate your co-workers - 3-space indenting (which is one of my favorites), indented braces, braces indented a different amount than the standard indent, nested code blocks which aren't indented, non-nested code blocks which are indented, "unit testing" your language of choice by assigning variables then testing the assignment, pseudo-Hungarian notation use of "v" prefixes (to indicate "variable"? We also use "z" to prefix form elements :/). Sadly, while I didn't lift the actual example from our code base, it definitely originates there in spirit - each of the styles in that block is well represented in the code I have the pleasure of maintaining every day.
  • (cs) in reply to Steve
    Steve:
    Or, y'know, you could let version control do its job and not leave redundant code all over the place.
    This. There is NO excuse beyond laziness or ignorance for having redundant code like that or, worse, having commented out code blocks "just in case" or // Ticket #42: Fixed frobulation of hobnobs to correctly grouse the hobnob -jsmith type of comments.
  • Crabs (unregistered)
    Who doesn't love using Exceptions to govern program flow?

    I did this on one of my first professional projects. It started as try{ some stuff } catch(MyException ex){ some other stuff } catch(Exception ex){ a real error }

    Not sure why I decided to do this, but it turned into about 10 different catch statements. I thought it was a fun way to do things. That software is gone now, so good riddance.

  • Crabs (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    Steve:
    Or, y'know, you could let version control do its job and not leave redundant code all over the place.
    This. There is NO excuse beyond laziness or ignorance for having redundant code like that or, worse, having commented out code blocks "just in case" or // Ticket #42: Fixed frobulation of hobnobs to correctly grouse the hobnob -jsmith type of comments.

    I comment out code all the time. It's usually because I'll want to use parts of it during the rewrite of the function, but I'm not sure what yet. I usually delete it after I'm done. Sometimes I forget.

  • (cs) in reply to Honnza
    Honnza:
    if (dncrptList.Contains(destName))
    {
       dId = SymmetricMethod.Decrypto(id);
    }
    else
    {
       dId = SymmetricMethod.Decrypto(id);
    }
    

    isn't a WTF. It happens when the logic changes frequently. Rather than merge the two branches and then try to remember what the condition was when the logic requests diverging pathways, you simply leave an if statement stub that you can expect later.

    Coding to specification is like walking on water. It's easier when it's frozen.

    Agreed. We have similar situations in our coding.

  • Gibbon (unregistered) in reply to Drake
    Drake:
    Frank:
    for (;;) {
    I think there's a new emoticon in there somewhere for that sick feeling you get when the fog of code smell lifts to reveal an actual rotting corpse.

    New emoticon? Why not Zoidberg?

    (;;) {

    I actually giggled. Featured comment?

  • Anonymous Paranoiac (unregistered) in reply to Gibbon
    Gibbon:
    Drake:
    Frank:
    for (;;) {
    I think there's a new emoticon in there somewhere for that sick feeling you get when the fog of code smell lifts to reveal an actual rotting corpse.

    New emoticon? Why not Zoidberg?

    (;;) {

    I actually giggled. Featured comment?

    Real programmers do not giggle.

  • (cs) in reply to Anonymous Paranoiac

    They do LOL instead.

  • Anonymous Paranoiac (unregistered) in reply to Nagesh
    Nagesh:
    They do LOL instead.

    Precisely. Perheps "heh" or even even "hehe". But not "lolol" (you're laughing out loud out loud? or is it laughing out laughing out loud?). Certainly never "lulz" or "lawlz".

  • Sizik (unregistered) in reply to Gibbon

    (/)(;,,;)(/)

  • Anonymous Paranoiac (unregistered) in reply to Anonymous Paranoiac
    Anonymous Paranoiac:
    even even

    We need an 'edit' feature.

  • Anon (unregistered)

    The link in the title is bad, it's relative and prompted me to download a-simple-misunderstanding.aspx

  • Sarten X (unregistered)

    The first and last samples are just weird. I suspect the original programmers were just a bit... ...loopy.

  • Anonymous Coward (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    Steve:
    Or, y'know, you could let version control do its job and not leave redundant code all over the place.
    This. There is NO excuse beyond laziness or ignorance for having redundant code like that or, worse, having commented out code blocks "just in case" or // Ticket #42: Fixed frobulation of hobnobs to correctly grouse the hobnob -jsmith type of comments.
    At my last job our rationale for doing this crap was a combination of "we've always done it this way" and "only managers have write access to the code repository."

    I'll let that second point sink in for a bit.

  • foo (unregistered) in reply to Anonymous Paranoiac
    Anonymous Paranoiac:
    Nagesh:
    They do LOL instead.

    Precisely. Perheps "heh" or even even "hehe". But not "lolol" (you're laughing out loud out loud? or is it laughing out laughing out loud?).

    It's lolling out loud, d'oh.

  • Anonymous Caruso (unregistered) in reply to Sarten X
    Sarten X:
    The first and last samples are just weird. I suspect the original programmers were just a bit... ...loopy.

    YEAHHHHH!!!

  • caecus (unregistered) in reply to Anon
    Anon:
    The link in the title is bad, and it should feel bad
    FTFY
  • (cs) in reply to Crabs
    Crabs:
    ObiWayneKenobi:
    Steve:
    Or, y'know, you could let version control do its job and not leave redundant code all over the place.
    This. There is NO excuse beyond laziness or ignorance for having redundant code like that or, worse, having commented out code blocks "just in case" or // Ticket #42: Fixed frobulation of hobnobs to correctly grouse the hobnob -jsmith type of comments.

    I comment out code all the time. It's usually because I'll want to use parts of it during the rewrite of the function, but I'm not sure what yet. I usually delete it after I'm done. Sometimes I forget.

    Oh fuck off! What's wrong with // Ticket #42: Fixed frobulation of hobnobs to correctly grouse the hobnob -jsmith?

  • Jon (unregistered) in reply to Anonymous Paranoiac

    The more ancient segments of the code base at work are littered with things like:

    while (foo) {
      if (bad_condition) goto 99
      *snip*
      99:
      continue
    }
    

    Of course, the language it's written in doesn't actually support while loops (well, not as while loops). Or curly braces.

    Occasionally, you'll even see:

    10:
    if (loop_condition) {
      *snip*
      goto 10
    }
    

    We obviously kill these things on sight.[/quote]

    I'd be curious to see how you write assembler code without them.

  • neminem (unregistered) in reply to Steve
    Steve:
    Or, y'know, you could let version control do its job and not leave redundant code all over the place.
    Fair enough. I am Adam, it amused me to see something I'd noticed appear here for the first time, and I will mention that, while I did find a copy of this particular small project in our svn, it wasn't the most recent version of the project, compared to one that had been fiddled with by one person, then passed by email to someone else to fiddle with it. And yes, that is definitely what version control is for.

    Another fun fact about the same project: when I got to the project, every time it was called (which was every http request for a particular site), it took a statically-defined array of literal strings, iterated through that static array adding each element to a new List, then did a Contains on that List to see if the page was whitelisted. Why the original coder (who I have honestly no idea who it was; nobody actually in our office, I don't think) didn't just define a static List with the whitelist strings instead, I'm pretty baffled. (I know, iterating through a list of a dozen or so strings creating a new list takes basically 0 time compared to an actual http request, and premature optimization is the devil and stuff, but it was just so bafflingly -ugly-, I had to fix it.)

  • (cs) in reply to Sizik
    Sizik:
    ((censored))
    Do not invoke Codethulu!
  • Berislav (unregistered)

    In the first example, the RWTF is not escaping the quotes in the echoed string, right? ;-)

  • Your Mom (unregistered)

    The last one should happen in any untyped language with a for each construct.

    Works in python, at least

    category = [4,5,6,7]
    for category in category :
        print category
    print category
    
  • Anonymous (unregistered) in reply to Matt Westwood
    Matt Westwood:
    Oh fuck off! What's wrong with // Ticket #42: Fixed frobulation of hobnobs to correctly grouse the hobnob -jsmith?
    Because that information is properly logged already if your commit message reads "Ticket #42: Fixed frobulation of hobnobs to correctly grouse the hobnob" and you are logged into git or SVN or whatever as jsmith?
  • (cs)
    for (;;) {
    

    Ugh. That has to be some kind of amateurish attempt at micro-optimization. That completely missed the mark.

  • (cs)

    Could this be an example of a poorly-done fix?

    try { if (_staff == null) throw new NullReferenceException(); } catch (NullReferenceException) { _staff = _provider.GetStaff(); }

    Perhaps the original just threw and later someone said to handle it and it was fixed by a moron.

  • instigator (unregistered) in reply to VS
    VS:
    This is not a WTF!

    Long time ago, before the while loop existed, this was the available loop with scope.

    for(;;) { // do stuff if (something) break; }

    Why wouldn't you put your conditional in the for statement? For that matter why not put your declaration and iteration in the for statement to?

  • AnonymouseUser (unregistered)

    Once again we're missing information to tell if the code is a real WTF or if it was valid given the date it was written, the language it was originally written in, the circumstances, well any sort of background.

  • Bob (unregistered) in reply to VS

    Abusing the for construct to emulate a for loop is a wtf.

  • Martin (unregistered)
    echo "<input type="text" name="row[]">
    ";

    This is a syntax error...

    In any case, TRWTF is having such a clunky for look in a "high-level" language in the first place.

    And John found this one, which demonstrates PHP’s “flexibility”: foreach ($category as $category) {

    While this is not a good way to program stuff, it's not one of those strange PHP quirks.

    Python:

    >>> a = [1, 2, 3]
    >>> for a in a: print a
    ...
    1
    2
    3
    >>> a
    3
    

    Ruby says:

    irb(main):001:0> a = 1..3
    => 1..3
    irb(main):002:0> for a in a do puts a end
    1
    2
    3
    => 1..3
    irb(main):003:0> a
    => 3
    
  • (cs) in reply to Anonymous Coward
    Anonymous Coward:
    ObiWayneKenobi:
    Steve:
    Or, y'know, you could let version control do its job and not leave redundant code all over the place.
    This. There is NO excuse beyond laziness or ignorance for having redundant code like that or, worse, having commented out code blocks "just in case" or // Ticket #42: Fixed frobulation of hobnobs to correctly grouse the hobnob -jsmith type of comments.
    At my last job our rationale for doing this crap was a combination of "we've always done it this way" and "only managers have write access to the code repository."

    I'll let that second point sink in for a bit.

    Then you have two WTFs.

  • foo (unregistered) in reply to chubertdev
    chubertdev:
    Anonymous Coward:
    At my last job our rationale for doing this crap was a combination of "we've always done it this way" and "only managers have write access to the code repository."

    I'll let that second point sink in for a bit.

    Then you have two WTFs.

    Don't say these words! Now someone's gotta make a lame regex pun.

  • n_slash_a (unregistered) in reply to Nagesh
    Nagesh:
    Honnza:
    if (dncrptList.Contains(destName))
    {
       dId = SymmetricMethod.Decrypto(id);
    }
    else
    {
       dId = SymmetricMethod.Decrypto(id);
    }
    

    isn't a WTF. It happens when the logic changes frequently. Rather than merge the two branches and then try to remember what the condition was when the logic requests diverging pathways, you simply leave an if statement stub that you can expect later.

    Coding to specification is like walking on water. It's easier when it's frozen.

    Agreed. We have similar situations in our coding.

    This is why comments were invented:

    // Note: Requirement_xyz was deleted, thus both branches of this if-statement are the same.
    // We are leaving it this way in case the requirement changes again.
    if (dncrptList.Contains(destName))
    [snip]
    
  • (cs) in reply to foo
    foo:
    chubertdev:
    Anonymous Coward:
    At my last job our rationale for doing this crap was a combination of "we've always done it this way" and "only managers have write access to the code repository."

    I'll let that second point sink in for a bit.

    Then you have two WTFs.

    Don't say these words! Now someone's gotta make a lame regex pun.

    You start with one lame pun. Then you post it in a comment on TDWTF. Then you have two lame puns.

    Something like that?

Leave a comment on “A Simple Misunderstanding”

Log In or post as a guest

Replying to comment #:

« Return to Article