The horrible if block



  • This isn't that bad but it made me cry a little when  I saw it.

     

    foreach(string keepString in stringsArray)
    {

        bool keepString= false;
       
        if (goodStrings.Contains(stringToTest))
            keepString = true;

        if (keepString)
        {
            continue;
        }
        else
        {
              ...
        }
    }


  • Winner of the 2016 Presidential Election

    So keepString is both a string and a bool, while stringToTest is undefined?  WTF!



  • i would imagine stringToTest is defined elsewhere, perhaps as a global variable so that way its value doesn't have to be passed to each individual function, although this looks like C# or Java, never really used either, but it looks like a functional language of sorts, so it would be easier to make stringToTest global instead of passing it through as a function call in every underlying function when it is not needed in them, but yeah to define keepString as a string and a bool, that gets tricky. basically dog = true or false, if dog is true or false, the output of such a variable would only yield the words true or false after checking its condition in the if block. so much fun for everyone.



  • Nah, I think that's a typo. I'm guessing the original code began:

    foreach(string stringToTest in stringsArray

    The wtf is the craziness with the ifs.
     



  • [quote user="teedyay"]

    Nah, I think that's a typo. I'm guessing the original code began:

    foreach(string stringToTest in stringsArray

    The wtf is the craziness with the ifs.
     

    [/quote]

    <font face="courier new,courier">...
    if (goodStrings.Contains(stringToTest))
        keepString = true;

    </font><font face="courier new,courier">if (keepString)
    ...</font>

    <font face="courier new,courier"><font face="tahoma,arial,helvetica,sans-serif">Note the empty line between the keepString = true and if (keepString), you'll never know if the CPU is slow enough to completely store all the bits representing the value of true to the memory address of keepString before it execute the continue command. The if (keepString) serves as a counter check.

    Also note the spaces and indentations, these are buffers so the CPU has enough idle time for the current command to complete before executing the next command.



    </font></font>



  • Also
    note the spaces and indentations, these are buffers so the CPU has
    enough idle time for the current command to complete before executing
    the next command.

    That's also why the code is in lower case. If you put code in ALL CAPS the processor thinks you arre shouting and executes the code faster.
     



  • Having seen the original code, you're correct -- the variable in the foreach should be stringToTest. I will beat scott with a cardboard tube for typoing.



  • [quote user="Cosmo7"]

    Also
    note the spaces and indentations, these are buffers so the CPU has
    enough idle time for the current command to complete before executing
    the next command.

    That's also why the code is in lower case. If you put code in ALL CAPS the processor thinks you arre shouting and executes the code faster.
     

    [/quote]

     

    never knew that 



  • [quote user="Cosmo7"]

    Also note the spaces and indentations, these are buffers so the CPU has enough idle time for the current command to complete before executing the next command.

    That's also why the code is in lower case. If you put code in ALL CAPS the processor thinks you arre shouting and executes the code faster.
     

    [/quote]
    <font face="tahoma,arial,helvetica,sans-serif">Great! I've learned something new again, thanks!



    </font>


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.