The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

The reason for redundant code

Last post 10-08-2008 3:34 AM by XIU. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 10-04-2008 9:50 AM

    The reason for redundant code

    It saves you from having to learn those pesky boolean operators... 

    if( ((input1 < '1') && (input1 > '9')) ||
    ((input2 < '1') && (input2 > '9')) )
    return INPUT_ERROR;

    input1 -= 48;
    input2 -= 48;

    if( ((input1 < 1) || (input1 > 9)) ||
    ((input2 < 1) || (input2 > 9)) )
    return INPUT_ERROR;

     

  • 10-04-2008 4:10 PM In reply to

    • Zecc
    • Top 50 Contributor
    • Joined on 06-12-2007
    • Location, Location, Location
    • Posts 654

    Re: The reason for redundant code

    Hey! do you have something against code reuse?
    If mixed metaphors were illegal, I'd be having an indigestion.
    typeof NaN == 'number'
  • 10-05-2008 5:18 AM In reply to

    • TGV
    • Top 200 Contributor
    • Joined on 10-09-2005
    • Posts 165

    Re: The reason for redundant code

    If you read carefully, you'll see that the code was not exactly reused. The condition in the first if-statement always fails.
  • 10-05-2008 8:22 AM In reply to

    Re: The reason for redundant code

    TGV:
    If you read carefully, you'll see that the code was not exactly reused. The condition in the first if-statement always fails.
    Not always.  What if it's double threaded and those two values change between the evaluation of whether they're less than 1 and greater than 9?

    SpectateSwamp exposing aliens. Obviously the World needs SSDS


    [10:07] <fatdog> so from now on.. be sure to wear nice clean underwear
    [10:07] <mps> fatdog: That is simply not going to happen
  • 10-05-2008 10:50 AM In reply to

    Re: The reason for redundant code

    belgariontheking:
    What if it's double threaded and those two values change between the evaluation of whether they're less than 1 and greater than 9?
    A good compiler should optimize away the second memory read (or the complete comparison), i.e. you have to declare the variables volatile for that to happen. Or you can overload the operator.
  • 10-05-2008 12:08 PM In reply to

    Re: The reason for redundant code

    strcmp:
    you have to declare the variables volatile for that to happen
    How do you know they aren't declared volatile in that snippet?
    ╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.

    #TDWTF @ SlashNET was merged into #codelove @ the same network. You're still welcome to drop by. I guess.
  • 10-05-2008 3:33 PM In reply to

    Re: The reason for redundant code

    Spectre:
    strcmp:
    you have to declare the variables volatile for that to happen
    How do you know they aren't declared volatile in that snippet?
    Easy:
    Spectre:
    they aren't declared volatile in that snippet
  • 10-06-2008 12:16 PM In reply to

    Re: The reason for redundant code

    strcmp:
    Spectre:
    strcmp:
    you have to declare the variables volatile for that to happen
    How do you know they aren't declared volatile in that snippet?
    Easy:
    Spectre:
    they aren't declared volatile in that snippet
    They aren't declared at all in the snippet.
    : IF` 0=GOTO` ORIG ;
    : THEN` HERE SWAP ! ;
    : ELSE` GOTO` ORIG SWAP THEN` ;


    gopher://zzo38computer.cjb.net/
  • 10-06-2008 1:26 PM In reply to

    • AlpineR
    • Top 500 Contributor
    • Joined on 11-17-2005
    • Washington, DC
    • Posts 84

    Re: The reason for redundant code

    operator<( const InputType& i, const char& c ) { return rand() < int(c); }

    operator<( const InputType& i, const int& n ) { return int(i) < n; }

     

  • 10-08-2008 3:34 AM In reply to

    • XIU
    • Top 150 Contributor
    • Joined on 01-08-2007
    • Belgium
    • Posts 208

    Re: The reason for redundant code

    dear sir, the rand() keeps changing, how can i fix this?
Page 1 of 1 (10 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems