Making it look difficult



  • Since I've hit the motherload recently, i might as well share it. 

    bool PaulaClass::DeleteIgnoredABC(const string& a, const string& b, const string& c)
    {
      bool retw = false;
      string *valueStr = 0;

      try
      {
        valueStr = new string(a+b+c);

        if(iDeleteIgnoredABC.contains(valueStr))
          retw = true;
        else
          retw = false;
      }
      catch(...)
      {
        delete valueStr;
        valueStr = 0;
      }

      delete valueStr;
      valueStr = 0;

      return retw;
    }

    Can in fact be written as (why noone has noticed this yet? i don't know):

    bool PaulaClass::DeleteIgnoredABC(const string& a, const string& b, const string& c)
    {
      return iDeleteIgnoredABC.contains(a+b+c); // why even use a function?
    }



  • Someone needs to sit that person down for a little one-on-one. It looks like there is paranoia of everything throwing an exception when obviously Contains won't do that.



  • It's completely error proof!



  • @GuntherVB said:

    valueStr = new string(a+b+c);
     

    looks like the author came from Java.  He might not know you can have an object on the stack. 


Log in to reply
 

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