- 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
Woah! Did he/she miss the point! OMGLOLWTFBBQ!
Admin
Yeah, using "else if" would make that code run way faster, especially if you optimize to put the common cases upfront. :)
Admin
Now that really makes me say WTF! That's like inventing the wheel and trying to roll it SIDEWAYS!!
Admin
You know, the funny thing about this comment is that you, too, absolutly missed the real point about what is wrong with the code ;)
Just a hint: The concept is called virtual function...
Admin
What's even funnier is that your sarcasm detector seems to be on the fritz again.
Admin
Actually had to read that twice to figure out what the developer was trying to do.
Where I come from, we call that going around your elbow to get to your thumb, or schedule in this case.
Admin
I'm pretty sure that comment was made in jest. The :) at the end kinda gives it away.
Admin
switch anyone?
or even using GetType() and using that to cast directly would have worked too.
Admin
The even funnier thing about this comment is that you, too, absolutely missed the point of Optimizer's comment.
Just a hint: sarcasm. :)
Admin
Someone forgot to parse the sarcasm tag. :)
Admin
Don't know api, but i guess he could have just:
nextScheduledTask = schedule.GetNextScheduledTask(startRunTime, true);
or am I missing something.
Admin
Admin
Admin
For those that missed it the first time, let me help you out:
Admin
He was very close to a major breakthrough. Yes, this would have worked--but he first needed to add GetNextScheduledTask to the interface, which would have prevented the code from compiling unless the classes all implemented the method, which would have then made the above code valid.
Admin
Seriously, shouldn't people just assume that people who are blatantly explaining the WTF and what they should have done are generally doing it in a sarcastic manner?
Just stop trying to correct people, people.
Admin
Using If or else If or whatever is completely unnecessary--the programmer is trying to make use of Class Factories--and doing a very bad job at it. He missed one simple point--put the GetNextScheduledTask method in the interface.
Admin
Admin
Seeing that makes me sad. Poor guy worked so hard to get that far and missed the boat. Hopefully he figured that out on his next project. (Perhaps after all of his co-workers mocked him?).
Admin
Admin
Wheel suck.
(or in this case) Interface suck.
Admin
I suspect that to misuse a class this badly, he probably didn't write the class to begin with.
It was probably written by another, more competent programmer and this guy was given the task of using it.
Admin
Admin
Has this guy not heard of virtual table lookups???
Admin
All right, I might get blasted for this, but I think you want "(i.e.: you are correct)" instead of the eg. It's a minor annoyance I have ;) EG means "For example" and IE means "In other words"
/Knowing is half the battle
Admin
Slightly off topic: I've seen many, many uses of "i.e." (id est = that is) to mean "e.g." (exempli gratia = for example) but I think that's the first time I've seen someone use "e.g." when "i.e." was the correct term.
Admin
Edit to include quote: Slightly off topic: I've seen many, many uses of "i.e." (id est = that is) to mean "e.g." (exempli gratia = for example) but I think that's the first time I've seen someone use "e.g." when "i.e." was the correct term.
Admin
Admin
I think it's good for people to know the difference. In some of the code I maintain, I've sometimes seen i.e. and e.g. used incorrectly in such a way that complicates what the writer was trying to say.
Admin
I too often see code like this, why bother define and use interfaces if you going to stick in a static if/else or switch block anyway.
Get rid of the id and a single line solves your issues:
IScheduledTask nextScheduledTask = schedule.GetNextScheduledTask(startRunTime, true);
I'm currently reviewing code and have come across the following so many times:
boolean rtn = false; if ( <expression> ) { rtn = true; } return rtn;
Review comment:
how about using the following boolean rtn = <expression>;
Admin
and he was so close to having it right! so close....
Admin
Poor guy. He was so close.
Admin
So, he should have used reflection to find a method with the appropriate name and signature to solve the job?
Admin
or simply return <expression>?
Admin
It took me a while to figure out what the heck was going on here, because Java implements all methods as virtual functions automatically and I forgot that in some languages you have to actually declare them as such.
As to the WTF: Wow.
You can tell this was written by someone who read the first page of a textbook section, but didn't bother reading the rest of it...
Admin
Maybe I'm missing something, but it looks like the typical way people have to code around the limitations of statically typed languages such as Java in order to implement polymorphism.
Admin
Hey! Don't diss on statically-typed languages, at least with them 2 + 2 = 4 always, and not "22" as I might get with the typeless languages. Oops!
Heh, reading this code feels like Deja Vu ... I remember watching a similar block of "else if / instanceof" sentences on a fellow student's Java code back in 2004. Thing is, the teacher was lecturing on... polymorphism. Looks like some of them didn't get the idea...
Admin
"schedule" is one of those words that cease to make any rational sense after staring at it too long.
Admin
Admin
Really, WTF?
Not related.
Admin
Admin
And don't bother saying "But with duck typing, the classes don't have to explicitly implement an interface, so it can be used with classes that you have no control over". Instead, answer me this question: how likely is it that classes that were not designed to an explicitly defined common interface would share methods with the same name, signature and purpose?
Admin
I guess you need to understand OOP to understand this WTF...
Even reading the comments, I don't get the WTF. :(
Admin
Admin
How about someone explain this to those of use who aren't full time coders.
Admin
http://en.wikipedia.org/wiki/Virtual_functions
Admin
An interface defines a common set of properties and methods. Any classes that claim to implement those interfaces must implement all properties and methods of the interface.
The assumption here is that all of the distinct types of Schedule (DailySchedule, WeeklySchedule etc.) implement the interface Schedule, and the interface Schedule specifies the GetNextScheduledWhatever method. We can assume the first point because the code sticks the object in a variable of type Schedule. The second we can't assume, but if Schedule doesn't specify GetNextScheduledWhatever when all of it's implememtors do then that's a WTF in itself.
But, if our original assumption is correct, the compiler / runtime knows that every Schedule implements GetNextScheduledWhatever. As a result, the coder can call GetNextScheduledWhatever on any object that is an instance of Schedule, without knowing it's native type (DailySchedule, WeeklySchedule, etc.). The WTF is that apparently the coder didn't know this, so he did a complex type-casting exercise, that was completely unnecessary...
You know, I never realised the concept of Interfaces was so difficult to explain. I think I might actually be feeling pity ofr the coder of this WTF after all... ;^)
Admin
I'd also be willing to bet that, in the code JP was reviewing, <expression> was quite often along the lines of <bThis == true && bThat == false>. I can't count the number of times I saw that in other people's code when I was doing my MSc. Enough to make an experienced programmer weep...
Admin
Oh, a sarcasm detector, that's a REAL useful invention <detectorExplodes />
Admin
I've seen code like that:
switch(pObj->GetType()) { case Type1: delete (ObjectType1*) pObj; break; case Type2: delete (ObjectType2*) pObj; break; case Type3: delete (ObjectType3*) pObj; break; case Type4: delete (ObjectType4*) pObj; break; }
Apparently, a concept of virtual destructor has escaped the designers. This code might be running in your laptop, controlling your soft modem.