Double negative



  • So I've just found the following useful little method in our code-base:

         bool NoErrors();

    It does pretty much what you'd expect. Checks for a bunch of possible error conditions then returns true if there are no errors or false if there are. The only problem is that every single time it's used (which is a lot), it's:

        if ( !NoErrors() ) {
            //Do some stuff
        } else {
            //Do some other stuff
        }

     

    It's not a huge WTF, but every single time I see it I have that jarring fraction of a second while I parse the double negative.



  • @Niggle said:

    So I've just found the following useful little method in our code-base:

         bool NoErrors();

    It does pretty much what you'd expect. Checks for a bunch of possible error conditions then returns true if there are no errors or false if there are. The only problem is that every single time it's used (which is a lot), it's:

        if ( !NoErrors() ) {
            //Do some stuff
        } else {
            //Do some other stuff
        }

    It's not a huge WTF, but every single time I see it I have that jarring fraction of a second while I parse the double negative.

    public bool HasErrors() {

        return !NoErrors();

    }

    Fixed?  :)



  • @C-Octothorpe said:

    @Niggle said:

    So I've just found the following useful little method in our code-base:

         bool NoErrors();

    It does pretty much what you'd expect. Checks for a bunch of possible error conditions then returns true if there are no errors or false if there are. The only problem is that every single time it's used (which is a lot), it's:

        if ( !NoErrors() ) {
            //Do some stuff
        } else {
            //Do some other stuff
        }

    It's not a huge WTF, but every single time I see it I have that jarring fraction of a second while I parse the double negative.

    public bool HasErrors() {

        return !NoErrors();

    }

    Fixed?  :)

    Incomplete. You need this too:

    public bool HasNoErrors() {

        return !HasErrors();

    }



  • @Someone You Know said:

    @C-Octothorpe said:

    @Niggle said:

    So I've just found the following useful little method in our code-base:

         bool NoErrors();

    It does pretty much what you'd expect. Checks for a bunch of possible error conditions then returns true if there are no errors or false if there are. The only problem is that every single time it's used (which is a lot), it's:

        if ( !NoErrors() ) {
            //Do some stuff
        } else {
            //Do some other stuff
        }

    It's not a huge WTF, but every single time I see it I have that jarring fraction of a second while I parse the double negative.

    public bool HasErrors() {

        return !NoErrors();

    }

    Fixed?  :)

    Incomplete. You need this too:

    public bool HasNoErrors() {

        return !HasErrors();

    }


    public bool HasNoErrors()
    {
        bool hasErrors = HasErrors();
        if (hasErrors)
            return false;
        else if (!hasErrors)
            return true;
        else
            return FILE_NOT_FOUND;
    }



  • @mott555 said:

    @Someone You Know said:

    @C-Octothorpe said:

    @Niggle said:

    So I've just found the following useful little method in our code-base:

         bool NoErrors();

    It does pretty much what you'd expect. Checks for a bunch of possible error conditions then returns true if there are no errors or false if there are. The only problem is that every single time it's used (which is a lot), it's:

        if ( !NoErrors() ) {
            //Do some stuff
        } else {
            //Do some other stuff
        }

    It's not a huge WTF, but every single time I see it I have that jarring fraction of a second while I parse the double negative.

    public bool HasErrors() {

        return !NoErrors();

    }

    Fixed?  :)

    Incomplete. You need this too:

    public bool HasNoErrors() {

        return !HasErrors();

    }


    public bool HasNoErrors()
    {
        bool hasErrors = HasErrors();
        if (hasErrors)
            return false;
        else if (!hasErrors)
            return true;
        else
            return FILE_NOT_FOUND;
    }

    HA!  I bet you thought it couldn't possibly be any worse, but I did it!!  Mwahahahaha...

    public bool HasNoErrors()
    {
        bool hasErrors = HasErrors();
        if (hasErrors == false)
            return false;
        else if ((!hasErrors != false) == true)
            return true;
        else
            return FILE_NOT_FOUND;
    }



  • No comments?  How am I supposed to understand what's going on here without comments in your code???



  • @Peraninth said:

    No comments?  How am I supposed to understand what's going on here without comments in your code???
    I'm not about to start a good habit...



  • @C-Octothorpe said:

    HA!  I bet you thought it couldn't possibly be any worse, but I did it!!  Mwahahahaha...

    public bool HasNoErrors()
    {
        bool hasErrors = HasErrors();
        if (hasErrors == false)
            return false;
        else if ((!hasErrors != false) == true)
            return true;
        else
            return FILE_NOT_FOUND;
    }

    If by "worse" you mean "doesn't even work" then yes, you made it worse.


  • @C-Octothorpe said:

    HA!  I bet you thought it couldn't possibly be any worse, but I did it!!  Mwahahahaha...

    public bool HasNoErrors()
    {
        bool hasErrors = HasErrors();
        if (hasErrors == false)
            return false;
        else if ((!hasErrors != false) == true)
            return true;
        else
            return FILE_NOT_FOUND;
    }

    Not enterprisey enough! You need this:

    public EnterpriseBoolean HasNoErrors()

    {

      EnterpriseBoolean hasErrors = new EnterpriseBoolean(HasErrors(), EnterpriseBooleanConfiguration.DoNotInvert);

      if (hasErrors.GetFalsitudinousness() > 0)

        return EnterpriseBoolean.MaximumFalsitudinousness;

      else if (hasErrors.GetFalsitudinousness() == 0)

        return EnterpriseBoolean.ZeroFalsitudinousness;

      else

        return EnterpriseBoolean.TruerThanTrue;

    }



  • @ekolis said:

    @C-Octothorpe said:

    HA!  I bet you thought it couldn't possibly be any worse, but I did it!!  Mwahahahaha...

    public bool HasNoErrors()
    {
        bool hasErrors = HasErrors();
        if (hasErrors == false)
            return false;
        else if ((!hasErrors != false) == true)
            return true;
        else
            return FILE_NOT_FOUND;
    }

    Not enterprisey enough! You need this:

    public EnterpriseBoolean HasNoErrors()

    {

      EnterpriseBoolean hasErrors = new EnterpriseBoolean(HasErrors(), EnterpriseBooleanConfiguration.DoNotInvert);

      if (hasErrors.GetFalsitudinousness() > 0)

        return EnterpriseBoolean.MaximumFalsitudinousness;

      else if (hasErrors.GetFalsitudinousness() == 0)

        return EnterpriseBoolean.ZeroFalsitudinousness;

      else

        return EnterpriseBoolean.TruerThanTrue;

    }

    try {
        // get factory from factory factory
       AbstractHasErrorsWebServiceClientFactoryImpl factory = AbstractHasErrorsWebServiceClientFactoryFactoryImpl.getAbstractHasErrorsWebServiceClientFactoryImplInstance();
    } catch (AbstractHasErrorsWebServiceClientFactoryNotFoundException e) {
        ....
    }
    
    // get client from factory
    try {
        HasErrorsWebServiceClientImpl client = factory.getHasErrorsWebServiceClientImplInstance();
    } catch (HasErrorsWebServiceClientNotFoundException e) {
       ....
    }
    
    // XML serialize object and send it to HasErrors WS to check for errors
    try {
        client.sendRequest(this);
    } catch (HasErrorsWebServiceClientHttpException e) {
        ....
    } catch (HasErrorsWebServiceClientInvalidArgumentException e) {
        ....
    }
    
    try {
        HasErrorsWebServiceClientResponseImpl response = client.receiveResponse();
    } catch (HasErrorsWebServiceClientHttpException e) {
       ....
    }
    
    return response.getHasErrorsValue();


  •  Use a SOAP call.



  • @dhromed said:

     Use a SOAP call.

    Everybody knows SOAP is too lightweight and non-extensible for Enterprise use.



  • @Sutherlands said:

    @C-Octothorpe said:

    HA!  I bet you thought it couldn't possibly be any worse, but I did it!!  Mwahahahaha...

    public bool HasNoErrors()
    {
        bool hasErrors = HasErrors();
        if (hasErrors == false)
            return false;
        else if ((!hasErrors != false) == true)
            return true;
        else
            return FILE_NOT_FOUND;
    }

    If by "worse" you mean "doesn't even work" then yes, you made it worse.
    This still isn't abstract enough.
    public bool HasNoErrors()
    {
        if(HasErrors() == false)
            return true;
        if(!NoErrors() == false)
            return true;    
        return FILE_NOT_FOUND;
    }
    


  • That's why I love scripting languages. Javascript FTW:

    var a = FILE_NOT_FOUND;

    var func () {return a; }

    var hasErrors = function (a, b) {

       if (!!!a) {

         b();

       }

       return a;

    }

    hasErrors(error, func)

    Where error is an Object, a string (which may be an error (or success!) message or just an empty string), a null or an undefined variable.


Log in to reply
 

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