- 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
OMGWTFBBQ?
captcha: zork
Admin
OMGWTFBBQ.
With out a doubt.
Admin
And to think, my Intro to Programming Environments 152 lecturer said "Never worry about making efficient code - That's what optimizers are for!"
Admin
The best part was that they bother to QA code to check for these sort of things. It's so anti-WTF, this WTF doesn't deserve to be a WTF.
Admin
TRWTF is that there's actually a company which actively finds and sorts out WTFs.
Doing years, quarters, minutes, seconds but not hours... that made me laugh out loud
Admin
Yeah, because nothing says great class name like "enmCCLAppState".
Admin
Looks buggy to me as well. Doesn't this create a negative time span?
Admin
Apart from issues already mentioned, what I really hate about this code is that it offers the opportunity to provide random strings for HowToCompare, and then doesn't tell you if you got it wrong; instead it just returns some answer that may or may not have any relationship to the value you wanted.
Why not use an enum? And why not stick an "assert (false)" in that default clause?
Admin
Admin
This must be the real WTF!
Avoid double dynamic casts with:
AxxxxMxxxxBxxxx foo = p as AxxxxMxxxxBxxxx;
if(foo != null) _appState = (enmCCLAppState)foo.AppStateId;
Admin
Do note that if type information is not available at compile time, this is exactly what you have to do.
Admin
Or unavailable at runtime, as is the case if you've modules that can be plugged in at deployment. But, then the developer should have commented this to make the intention clear.
// lets try some reflection so I feel like I'm learnng something new today, and can convince myself I'm a real smartypants.
// I mean, why walk when you can double back flip?
captcha: creative
Admin
Admin
It's C# code which makes string comparisons via '=='
Admin
Yeah, and if it's supposed to be Lisp, they got all the parentheses in the wrong places. If it's supposed to be Perl, they forgot all the $ and @ signs. If it's supposed to be Haskell, they shouldn't be trying to use assignment statements.... etc, etc...
Admin
And it wouldn't use GetType, and it wouldn't use ToString, etc. etc. etc.
Yeah, it's not Java.
Admin
I have seen this code in a production system before. A little Google finds (among others)
http://www.aspfree.com/c/a/ASP.NET/DateDiff-function-in-C-to-simulate-VBScripts-by-Robert-Chartier/
I think someone liked the VB style DateDiff() and other just copied it in...
-Edoode
Admin
sweet. this is like putting a "Windows Timer" control upon every page and using it to determine when a button is enabled/disabled (such as login, view disclaimer, etc.) as some programmers/idjits want *total* control over what happens in their app.
<captcha: perfect splendid excellant YOUR still and geek go code something>
Admin
He may have told you that instead one should focus on simple code instead. If that gives speed gainst that is a nice extra. The most important thing in writing code is to make sure it is understandable by a reader. (Note that you too will have forgoten the code when asked to look at it half a year from now).
Admin
This whole CodeSOD is a waste of space. They are BORING!
Admin
Shut up before we're back to 1 post a day again. Even boring WTF's are good at wasting time.
Admin
The last one was hard to read, here's an easier version:
if (p.GetType().ToString() == "com.company.product.ABCWidget") {
Type myType = p.GetType();
PropertyInfo[] props = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
for (int i = 0; i < props.Length; i++) {
if (props[i].Name == "AppStateId") {
long val = Convert.ToInt64(props[i].GetValue(p, null).ToString());
_appState = (ABCState) val;
break;
}
}
}
if (p is ABCWidget) {
_appState = (ABCState)((ABCWidget)p).AppStateId;
}
Admin
someone find that stupid SOB who created that function and smack them. They give developers a bad name and fill up internet searches with crap!
Admin
It's not just quarters that's buggy. Dividing days by 365 won't get you years, either.
I like how you can pass in anything at all for the "how to compare" string and get back days. :)
Admin
Yeup... Sure 'nuff will.
Admin
I try to avoid anything written by Robert Chartier like the plague. Try reading some of his other articles on that same site. Yikes.
Admin
Wheres the XML? This CodeSOD is lame.
captcha: awesomeness
Admin
Show me a project written by you and I shall find reason to have you hanged. A good programmer is writes good code, no programer will always take the correct path. Judge by the frequence of errors, not by one stupid mistake.
edit: (this is meant as a general comment about programmers while referring to a 17 century philosopher, not toward Robert Chartier )
Admin
Admin
After studying the above code for a while to figure out what it did, the discoverer couldn't help but rewrite into a more efficient way to access a property:
Admin
All it needs is the beanbag girl back.
Admin
trwtf is that you acronymed trwtf
CAPTCHA: WTF
Admin
Re the reflection WTF: even if the class is loaded from a plugin at runtime it's still a WTF imho because it's hard to read. Either the class should implement an interface which is defined in the main assembly (in which case you could do
IWhatever thing = thing_to_test as IWhatever;
if(thing != null) _appstate = thing.AppState;
...) or the code to read a property via reflection ought to be refactored into a function and called:
_appstate = (AppState)ReadRuntimeProperty("Initech.Components.Whatever", "AppState");
Admin
Another RWTF is that he didn't bother adding 'h' as a case in the switch statement. It was a private function anyway, so he could just add it there. Seems like the right place to put it.
Admin
Augh! My ears!
Admin
> I try to avoid anything written by Robert Chartier like the plague...
Personally, I try to avoid anything written by Albert Camus like, "The Plague."
Admin
I'm curious why they're called the Van Gogh Awards?
Admin
Agreed. The fragility and almost-nonexistent error handling and is guaranteed to cause a nasty bug months or years down the road.
Of course, it's a WTF to use strings or enums or ints or anything else for this in the first place. Stop using kewl abbreviations and make seven different functions already (DifferenceInDays, etc.). No, the program will not be noticeably larger. Every professional knows that simple code is better than elaborate code.
Admin
In a perfect world you are absolutely correct. However, it's not like we always get to modify/build assemblies that we reference to. Yeah it needs clean up that's for sure.. Especially the part where it loops through all the properties in a for loop till it finds the right one. The point I am trying to make is, the suggest solution might not actually work because it's not equivalent to the original code.
Admin
<a href="http://en.wikipedia.org/wiki/Liskov_substitution_principle">Liskov</a> must be turning over in her grave. Oh wait, she's not dead yet.
Admin
I think the real WTF is that you have languages that don't make everyday tasks easier. For example, the above in CF is:
Admin
How can you possibly think that passing a string argument to a function for this is cleaner than using properties and overloaded operators?
You're probably just scared of the decimal conversion, but that's how strongly typed languages work. Maybe someday you'll learn one and understand.
Admin
timeSinceLastRefresh = DateTime.Now - cachedOn;
Admin
I know many languages, both strongly and weakly typed. I have no problem with the decimal conversion (other then it's an additional, step that should be implicit in the first place).
I do think that this code would be much cleaner:
Captcha: 1337
Admin
Wanna know the scariest part about this code? It's in a module used to approve multi-million dollar business loans.
"Every day's a new day" lol
Admin
Here are the WTFs I see:
Using a string for enumerated type; enums exist for a reason.
DateTime has a static operator- method, so (startDate - endDate) should work just as well. And unless they're switching the sign later this will result in a negative span. (Yes I know this has been pointed out.)
This is full of 'em:
Let the exception propagate, dammit! That's what exceptions are for. I'd hate to be the consumer of this method.
Admin
Aside from the real WTfery going on here.... what's with the fascination of passing an ascii string to describe the operation? Whatever happened to enums?
Admin
You can always take the process of reading the function and abstract it into a function. I agree that you can't always make the class implement an interface of your choice, though it is best if you can do it.
Admin
Uhm, I'm not exactly a C# guru, but are those two statements equivalent? Wont the second case generate some false positives? What happens if the user has Cxxxx.Cxxxx.Cxxxx.Wxxxx.AxxxxMxxxxBxxxx and Cyyyy.Cyyyy.Cyyyy.Wyyyy.AxxxxMxxxxBxxxx?
Admin