- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Filed under: I have reflected this article. Pray I do not reflect it further!
Admin
That formatting is super gross.
Admin
It makes me want to gouge out my eyes.
Admin
Is there none? If Java is like C#, overload resolution happens at compile time, but
instanceof
is a runtime operator. So: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...Admin
Yup. Completely correct. You sometimes have to do this sort of thing for multiple dispatch, or when working with poorly designed base classes.
Admin
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.
Admin
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.
Admin
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!
Admin
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.
Admin
Alright, I'm lost on the second part: Why would the first branch supposedly never evaluate true1?
Don't you mean
?
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?"
Admin
Obviously.
I blame lack of coffee.
Admin
did you try drain cleaner?
:trolleybus:
Admin
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....
Admin
I always assumed it meant that the code made him realize he had slept with his mother.
Admin
This conclusion is incorrect due to misunderstanding the code:
The reason for the if is stupid, yes, but it can actually be true. Suppose the caller did this:
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:
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?
Admin
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.
Admin
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
Admin
I thought we solved the halting problem.
Admin
so you don't have to do reflection if it's known validatable at compile time.