- 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
I really miss TDWTFs with a page or two of code listings. 10-line wtfs and a pretty description just can't cut it, it's like a gentleman's wtf compared to beasts like the hotel reservation system.
I wonder if they really did just leave all ten kids to their lonesome for almost two years, believing every progress report ("coming along great!"). Geez.
Admin
Better yet, use this extremely sophisticated and hard-to-understand syntax:
If you can put it into a foreach() loop, you can almost always pass it to the ArrayList constructor and get a copy of it.
Admin
Clearly the developers were not the only inexperienced people on this project....
-me
Admin
You don't see enough bad code at work? Last thing I want is to wade through pages of unreadable crap to get to the WTF. I'll take More Stories and Writeups for 200, Alex.
Admin
Here's someone who's never implemented a smart caching mechanism in his life, apparently. You realize that the "static variable" can be inside the class and referenced by the function, no? It doesn't have to be inside the calling function!
But it wasn't, given the juniors were likely around your skill level.
Admin
So.... What happens when getRols() returns null?
captcha: "foxtrot"!!! I <3 you too, Alex! :D
Admin
Admin
hey .Net Developer - please if you are going to rethrow an exception, just call throw, not throw e.
This will lose the stack trace and you will never see the real eror.
Admin
These words make no sense.
Admin
Mmm.... rolls. Got any sourdough, or potato rolls?
Admin
this:
Unhandled Exception: System.ArgumentNullException: Argument cannot be null
Well in mono anyway (not near a windows box)
Admin
It never should. If somebody has no roles, you should be returning the empty set, not null. That's why we use collections.
Admin
Perhaps one of them was the Spawn of Paula?
Admin
A lot of my fellow CS students were making this exact same mistake last term until I pointed it out to them.
Admin
Ah yes, but what if the number of roles returned by getrols was to decrease at just the right time?
Admin
Not that is a real WTF. Why in the name of all that is pure and holy would you just throw again! The whole idea of the try / catch is to gracefully handle errors, or to "throw a more specific error ie System.ArgumentNullException. But to catch an exception to only throw it again!
Admin
*snickers*
There are really just two fixes to this:
Admin
Agreed, but as the original poster commented - you may want to add logging at this point. I can not see any other reason why you would just rethrow, but if you are, at least do it in a way that so that you can work out where the real error came from.
Admin
Assuming that senior person really knows what he is doing as well. Once I was working as a junior programmer for a senior one who turned out to be less skilled than I was.
Admin
It's not? Let's ignore the whole question of intelligent names for methods and variables, which make this a nightmare to read, and look at the underlying logic: Instead of simply taking every value in getRols(), casting that value to a "RoleClass" (whatever the hell that is), and putting it back into that same datastructure using (at most) one loop, with (at most) one return, he adds an uneccesary conditional check, an uncesarry constructor call, a whole redundant datastructure (double your memory footprint, yee haw!) and a redundant return. And this is a really simple little method.
Anyone with half a brain should have known better than to call a function with an array if the damn array could be null. You should always do that first, so you don't have to re-implement it for every program you've got to call with that array.
Admin
I'll start by saying this is the first visit to www.thedailywtf.com .
While this article is what I would consider a "WTF?", the comments on here are by far worse. Don't criticize code you can't even read properly. My lord.
In 62 comments I think there there were 4 correct interpretations of the code. Still, none of the non-obvious aspects were touched, only the performance impact. What about the order of returned result sets from getRols().Item[roles.Count]? SQL does not guarantee order of result set, so there's no guarantee you'll get every record without duplicates. Even with an order by clause, if a row is inserted while inside the loop your order is hosed, and data integrity compromised.
On the importance chain Integrity > Performance always. If it takes 10 seconds to log on that sucks but if it does not log me on because it keeps skipping a record, that's "WTF".
I'll end by saying nice website... FireBug logged 4300 javascript errors as I typed this message(this.document.ftb has no properties) . That's my final WTF.
Admin
I have to admit, there are so many WTF's in that single function, which is only a measly 15 lines of code long, that it took me a few minutes just to catalogue them all.
First, unless I am mistaken, the fact that the function exists, seems like the biggest WTF. getRols() returns the exact same ArrayList as GetRoles() does, thus making GetRoles() unnecessary except for the fact that GetRoles() is a far better choice for a function name, thus bringing us to the next WTF, which is the name of getRols(). It absolutely drives me mad when programmers abbreviate words unnecessarily or just drop letters for no apparent reason.
Now assuming that GetRoles() actually served a purpose (which it doesn't) then, as others have correctly pointed out, the function seems to be written for the worst possible performance. Perhaps the programmers took it as a challenge to see which one of them could write the slowest function that did nothing in 15 lines or less. Calling getRols() in the conditional causes that function to be evaluated for each iteration of the while loop. Calling getRols() in the defitition of the loop causes getRoles() to be evaluated yet again for each iteration of the while loop. That means even if the getRols() procedure ran in linear time, the performance of GetRoles() would be 2n^2 best case! A better practice would be to call getRols() one time before the loop, store the arrayList it returns locally, store the ArrayList.Count into an integer locally, use that integer in the conditional of the while loop, and use the ArrayList Item array in the definition of the loop. This would yeild linear complexity for GetRoles(), if there was any purpose for GetRoles() in the first place (which as I mentioned there is not).
And as someone above pointed out, regardless of whether getRols hits the database or not, the above mentioned is still the case and its still a major WTF because every time getRols() is called unnecessarily it pushes a new instances of that function onto the stack, allocating memory and stealing cpu time unnecessarily. The fact that it does hit the database magnifies the problem because then it gets to steal time away resources from the machine the database resides on as well as eat network bandwidth.
Admin
Next time you think of coming here, go to www.thedailySTFU.com instead. I hate your attitude. Thanks in advance.
Admin
Darn, someone beat me to it! I was going to comment about how hungry this WTF made me. :-]
Admin
As you are new here you should be properly introduced to the forum software, Community Server 2.0.
Had you been around for Community Server 1.0 you would be quite familiar with the phrase "The real WTF is the forum software". While 2.0 seems to be 'better?' it does come with it's own bag of WTFs.
And you should also know that no matter how bad the WTF there is somebody that will try to defend or rationalize it.
Admin
Just imagine if you replaced getRols() with getPaula()?
Why, I bet it would be Enterprise Visual Web 2.0 XP SP ISO 9001 complient with that change alone!
Admin
Oh common guys, maybe the application was written to be a DB DOS application..... or not...
I think this is a commone jr. dev issue. As the story reads, they let the jr. devs go. The correct method to handle this is to hire the sr. dev on and do code reviews. By taking the route this company took, no one benifits long term. I call management WTF.
- SPT
Admin
I was being deliberatly jerky and figued it to be a good end note. Truth be told, I'm really fond of this inline rich text editor and the comment system is very nice. I write TONS of raw Javascript for Ajax and DHTML so I know how hard it is to catch all JS bugs which tend to be trivial. I could hop on a horse and say why didn't you use firebug to test in the first place, but I was only trying to be funny. (BTW firebug is completely awesome in the highest of high senses).
The content of the articles is very good and I do belive I'll become a more regular visitor. And yes, I'll lose the "attitude". ; - )
I just thought it was funny how many people said, "OMG it's always null what a bad programmer" or "here's a better (bloated) 25 line way of doing this extremely simple and redundant function". It had humor beyond the article itself.
Admin
Don't hate the Coder, hate the Code!
Admin
Sounds like Alex has been reading ActsofGord.com
Admin
Not always.
Very rare for something to be "always" in this business.
Sometimes a quick rough idea is good enough.
But nearly always, I'd have to give you that.
Admin
The Rock says know your role, and shut your damn mouth.
Admin
I came up with 2n+2.... It looks pretty linear to me...
Admin
<FONT size=4>Roles on the floor laughing</FONT>
Admin
Or even the following (using Java), which would avoid one redundant array copy operation.
public List getRoles() {
List roles = getRolesFromDB();
if (roles == null) {
return null;
}
return Collections.unmodifiableList(roles);
}
Admin
Actually in any sane programming language the variable HAS TO be inside the class to be called "static". And you obvously lack the skill of reading quotations that posts respond to.
Not to mention that you have a weird sense of caching implementation. Had this be a caching function, it would do something along the lines of "static foo = null; if (foo == null) foo = getRols(); return foo". Nothing even close to the crap posted above.
Admin
Ok GetRols is a call to a database, so that is two db hits for each role + 1 to retrieve a list of roles. If that does not make you scream I don't know wtf will.
CAPTCHA : Genius.
Admin
You're wrong. ArrayList contains functions (yes functions) that are not referentially transparent. This means that contract implementation identity ("newness" in Java/C#) is significant, hence the need to create a new ArrayList. If the type contained operations that were all referentially transparent, you would not care about implementation identity.
You can observe the effect of giving the authority to design a language - to people who are incompetent at the task (common euphemism: expert groups) - by observing some of the atrocities in both Java and .NET. Specifically, the "hiding of constructors" behind "factory methods" since it exposes less to the client (no implicit identity) and the type is referentially transparent. Trivia: why was java.lang.Integer#valueOf(int) introduced in 1.5 when Integer#Integer(int) already existed? FWIW, I no longer work on the 1.5 implementation.
It's Programming Language Theory 101 stuff, but it's ignored in the industry anyway.
Admin
There are basically three types of monkey programmers.
1) the fun little chimps. - they do all the ( happy ) banging on the keyboard.
2) the huge great apes. - they handle the ( serious ) oversight and governance.
3) the barrel *of* monkey(tm). - originally wooden, they provide the "out of the box" inspiration - and are often involved in marketing
Given these distinct and necessary concerns that makes up any good development team - it's not far fetched, that this code was truly Built-With-Pride by monkeys.
Admin
I am sorry to disagree. this is not a WTF. this is definitly a OMGWWTTO
(oh my god, what were they thinking of?!)
Admin
I'm right with you buddy. Except the person I'm under has 5 years on me.
Admin
Uh-huh. I am glad I stick with C++ most of the time. I just picked up a Java book the other day, and just when I thought I understood the concepts, all of this "factory" stuff came up. Thanks for clearing that up.
Admin
Uhh, thats nice!
In fact, why not let getRows() create a whole new ArrayList for every row in the database?
Its 2006 god damn it! We got enough space and hertz to do this!
Just do everything step by step. That creates roads over time.
Anyway...
As i said before, i should SO get a well paid job.
Even if im not the wiz of wizards, id so gonna kick their ass.
And to honor the day; this posts captcha.equals("craptastic") == true.
Admin
Oh, my, yes. Translating it into php certainly made it clearer...
...kinda like cleaning a window with mud.
Admin
Well said.
Admin
And you've heard of java.util.Collections.unmodifiableList(), right? The WTFery goes on and on...
Admin
<off topic>
Someone from opera obviously reads this forum, they have now introduced screen women to the sidebar to compete with foosball girl and beanbag girl!!!! Pretty pathetic attempt but hey shows someone is listning to the bable that goes on here!
</off topic>
Admin
They certainly were trying...the company's patience.
Admin
The real WTF is why Sumo Lounge girl isn't sitting on my lap instead.
Admin
Code like this is ugly, but it doesn't surprise me. I've been taking some CS classes at a state school near to where I live. In my experience, students can get away with writing code like this, and they are never corrected as long as their programs pass all the test cases. You can write horribly ugly and inneficient code, and still get an A as long as your program passes all the test cases and your code includes a sufficient percentage of comments.
I think the algorithm used to grade programming assignments must look something like this: