• (disco)
  • (disco)
                    }else{
                            if(     log.isDebugEnabled() &&
                                    objectToCheck != null &&
                                    objectToCheck.getClass().getPackage().getName().startsWith("com.initrode") &&
                                    !objectToCheck.getClass().getName().contains("Enum")
                                        ){
    

    That formatting is super gross.

  • (disco) in reply to LB_

    It makes me want to gouge out my eyes.

  • (disco)

    Yeah. So there is no planet in which the first branch would ever evaluate to true

    Is there none? If Java is like C#, overload resolution happens at compile time, but instanceof is a runtime operator. So:

    objectToCheck((Object)(new SomeValidatable()), "whatever");
    

    would correctly trigger the instanceOf branch and call the proper overload even though the object was downcasted to a more general type. It's wonky, but workable...

  • (disco) in reply to Maciejasjmj

    Yup. Completely correct. You sometimes have to do this sort of thing for multiple dispatch, or when working with poorly designed base classes.

  • (disco)

    Maye the original programer did know about assert()? Still the idea that you'd want different logic when in debug than in not is almost certainly a WTF.

  • (disco)

    Reminds me of a bright spark who committed a seriously gross WTF.

    The application crashed in a way that was completely inscrutable because, from the log files, we could not work out where it was crashing. But when we set the debug logger to "log everything" mode, it worked as expected. We discovered this after we had deployed it to Production and turned detailed logging off.

    For some reason if you actually ran it within a debugger, when it crashed it didn't give any help at all -- all you knew was that it failed "somewhere within the program".

    What our bright spark had done was perform a test which determined whether the debugger level was more detailed than fatal, and if so, do some business logic in order to generate a load of data which was then output to the log file. Later on, that same bright spark realised that this calculation for the logging process was repeated further downstream, so had merely removed the downstream code and widened the scope of the logged variables so they could be merely carried through instead of recalculated. Of course, nobody had ever removed the logging until we got to production and turned it off.

    The fact that the only logging level we had ever logged anything as was "detailed" (yes, even for errors) was a WTF of its own.

  • (disco) in reply to Fox
    Fox:
    It makes me want to gouge out my eyes.

    I'm always a bit bemused by people who utilize that form of expression.

    No. Stop it. You should want to gouge out the eyes of the person who wrote that, so they don't foist any more abominations on the world!

  • (disco) in reply to FrostCat

    Well, obviously that was my first instinct, but I don't actually know who wrote it, so I can't really gouge out their eyes.

  • (disco)

    Alright, I'm lost on the second part: Why would the first branch supposedly never evaluate true1?

    Maciejasjmj:
    Is there none? If Java is like C#, overload resolution happens at compile time, but `instanceof` is a runtime operator. So:
    objectToCheck((Object)(new SomeValidatable()), "whatever");
    

    would correctly trigger the instanceOf branch and call the proper overload even though the object was downcasted to a more general type. It's wonky, but workable...

    Don't you mean

    objectIsValid((Object)(new SomeValidatable()), "whatever");
    

    ?


    1: Although since nothing here actually returns, I suppose it'd be more accurate to say "why would the first branch always result in an exception?"
  • (disco) in reply to Dreikin
    Dreikin:
    Don't you mean

    Obviously.

    I blame lack of coffee.

  • (disco) in reply to Fox
    Fox:
    so I can't really gouge out their eyes.

    did you try drain cleaner?

    :trolleybus:

  • (disco) in reply to Dreikin

    I assume that "instanceOf" is equivalent to the "is" keyword in C#, in which case I'm not sure why the writer believes that it could never evaluate to true. If "objectToCheck" is an instance reference (which it should have to be) and "Validatable" is a Type reference, then I see no specific reason that the first branch could never evaluate to true. Maybe I have missed something....

  • (disco) in reply to FrostCat
    FrostCat:
    Fox:
    It makes me want to gouge out my eyes.

    I'm always a bit bemused by people who utilize that form of expression.

    No. Stop it. You should want to gouge out the eyes of the person who wrote that, so they don't foist any more abominations on the world!

    I always assumed it meant that the code made him realize he had slept with his mother.

  • (disco)

    This conclusion is incorrect due to misunderstanding the code:

    Yeah. So there is no planet in which the first branch would ever evaluate to true,,,,

    The reason for the if is stupid, yes, but it can actually be true. Suppose the caller did this:

        Object o = new WhateverObjectThatIsValidatable();
        validator.objectIsValid(o,"WhateverObject");
    

    Don't hassle me with, "The above is stupid," because I know that. Nevertheless, that kind of BS is seen in code all the time. And there are more clever examples: suppose we have class Geometry and its flood of 32 subclasses, some of which implement Validatable and some of which don't (Assume Geometry is from a library and can't be changed to implement Validatable.) This leads us to:

        Geometry g = new RectangleGeometry(100,100,200,200);
        validator.objectIsValid(g,"WhateverObject");
    

    Is a Geometry g Valadatable or not?

    Since the type of "o" or "g" can't be certified Validatable at compile time, the objectIsValid(Object, String) signature is going to be used. The if statement is checking to see if the object is of the type Validatatable because, if it is, then it needs to be routed to objectIsValid(Validatable, String).

    Except then, yes, it descends to the inane. First question: WTF didn't you just incorporate the three lines of code from objectIsValid(Validatable,String) into objectIsValid(Object,String) and do away with the former?

  • (disco) in reply to CoyneTheDup
    CoyneTheDup:
    Is a Geometry g Valadatable or not?

    Worse still, what happens when you have a factory method in the mix and you're checking the output of that? Sometimes it's just unreasonably hindering awkward to figure out everything at compile time.

  • (disco) in reply to FrostCat
    FrostCat:
    You should want to gouge out the eyes of the person who wrote that, so they don't foist any more abominations on the world!

    How dare you advocate mutilating the mentally ill, you morally bankrupt excuse for a human being.

    Filed under: coo, I speak English good, I learn it from a book

  • (disco) in reply to dkf
    dkf:
    Sometimes it's just unreasonably hindering awkward to figure out everything at compile time.

    I thought we solved the halting problem.

  • (disco) in reply to CoyneTheDup

    so you don't have to do reflection if it's known validatable at compile time.

Leave a comment on “Validate My Feelings of Cleverness”

Log In or post as a guest

Replying to comment #:

« Return to Article