- 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
<FONT style="BACKGROUND-COLOR: #ffffff">Don't overlook the unused parameters: lKey, iModifier, sKeyTxt</FONT>
Someone else already mentioned this. Thanks for reading the thread though.
Admin
Maybe this code was just used for debugging purposes?
Maybe the author wanted some hotkey handling, and created the function to set a breakpoint on the eval and inspect the key value in the debugger. He could have added the switch clause because he planned to add handling procedures for certain hotkeys later. But then, he noticed that the function never got called, and just forgot about it to eat some pie.
Admin
It's likely that this is simply the result of many changes by many people.. Maybe someone first put the outermost try/catch and more cases for the switch. Then these cases were noted to be wrong behaviour and were removed, leaving only default. And the default case needed try/catch, but nobody noticed that the outermost try/catch was now unnecessary. Actually, this train of thought can explain most of the WTFs posted here.. So if you want to keep humoring yourself with these snippets, thinking they were written by one person in one sitting, just ignore what I said here.
Admin
About the lamer-talk: If you can't even abstract away from the location of those curly braces, how can you call yourself a good coder? I find it interesting that it's only the people who uses an entire line for the leading brace that's complaining :)
About the WTF, i wouldn't really call this a WTF. I code like this all the time. You know, the interesting thing in coding and looking at other peoples code is to learn how other people thought while writing the code - get a little sneak-peak inside their mind. That's the entire reason we became coders in the first place, remember??? So it is VERY BAD PRACTICE to just remove code after you've changed your mind about how it should work - then the other people looking at it, wouldn't get into the thought-process you went through while you were coding the function. They wouldn't be able to follow your ideas and how you changed your mind about those. The code would loose it's continuity and thus become uninteresting for others to read. So the morale: NEVER remove code once it's been written!! It's unpolite and your code becomes gray and without soul!
So with that in mind, i think i know how this code came to life. Like first he wanted to catch the exception and just throw it away.. Like this:
Then he changed his mind, like "hmm.. maybe it's better to hand it to the calling function anyway". But he was polite, so instead of removing the try/catch, he changed it into something like this:
Then he maybe discovered that some other functions puked once in a while, so he changed his mind again. To avoid ruining the continuity of the code (as explained above) he didn't change the catch-statement again. He knew it would be better to make an new inner try/catch inside the other one:
Now everyone can still follow his thought-path, and the code still works as he wanted! weepee!!
The switch and id-variable ofcause came to life for the same reasons (he introduced them but then changed his mind again).
I will leave that for you to explore.
As i said, this is infact VERY GOOD code, which takes you on an interesting journey through time. The way all code should be!
Consider my words next time you write a function, and our world might become a much better place.
Admin
It's more that just a user knowledge issue. CVS and other version control systems have the ability to do automatic merges. I might be able to handle it, but if too many things change, the version control might just think the whole file is completely different. I've seen this happen with ClearCase when I clean up code. This causes a lot of problems for the rest of the team because whn they update their view, the version control requires they manually resolve the things that cannot be automatically merged.
If a cannonical form of the code were used to save the code, this problem would be decreased from the norm instead of increase.
Admin
History belongs in the source code control system. And trolls like you, belong under the bridge.
Admin
God I wish there was something that did that. I'm sick of merging loads of files that have some small but critical changes and have been autoformatted to a different style in eclipse so I have to look at practically every damn line.
Admin
This has got to be a troll.
And you expect people to think you're a good coder when you can't keep track of the subject of the sentence for your verb agreement? I'd hate to see your memory allocation discipline.
I rest my case.
That's what COMMENTS are for, not bad code. You know, the stuff after // like
<FONT face="Courier New">// this try-catch is for [short explanation]</FONT>
If you change your mind, and if you must keep the obsolete code in for whatever bizarre historical reasons, COMMENT OUT the parts that no longer make sense.
The thought process here is "I'm a moron."
You forgot to mention two other important advantages: 1) it uses more CPU cycles, which is a Good Thing, and 2) everybody can see what a nincompoop you are. [*-)]
I hope we never cross paths via a text editor. You've certainly failed any job interview you might be put through.
Admin
to rogthefrog and loneprogrammer
Guys lighten up! The above was obviously a joke. It's not even a troll either; to be that it has to be blatantly inflammatory, and perhaps have poor grammar and punctuation. Though it probably would have helped if the joker had used some sarcasm tags.
Admin
But the grammar WAS poor! [:D]
Admin
LOL!!!!!! I'm speechless.... You guys have no sense of humour what so ever :))
Anyway, your replies are just like pretty much avoiding the real issues of my post (good code vs. code without soul). Maybe you're afraid of the truth? :) Come on, you guys can do better! ;)
"And you expect people to think you're a good coder when you can't keep track of the subject of the sentence for your verb agreement? I'd hate to see your memory allocation discipline."
I'm just a bit tired of a tread once again getting hijaked by people who think their way of using parens are superiour. (kind a' lame, wouldn't you say?) (wot'z a verb, btw? :) )
Admin
I used to work with a guy that would copy/paste entire functions that he found on various internet sites into our code. Most of the time the functions where never actually called (or relevant for that matter). I don't know if he just didn't understand C++ or if he was just trying to look productive.
Admin
I stand corrected. You are a most excellent troll, though <a href="http://ehermit.conforums3.com/index.cgi?board=picturepost&action=display&num=1096746953>I refuse to feed you</a>.<br>
Admin
I have not laughed this hard in a long time
What ridiculous code
Admin
ok.ok.ok. That does it, I have registered! Lurker no more!
This one has compelled me to....astounding!
I'd like to believe the theory further up in this thread, that this is just a bad case of the "leftovers", but I'm just not so sure....wow
Admin
On the unused parameters. They may not be unused: they may, instead, serve to bind names locally for the eval. Take this as an example:
function f(a, b, c) { return eval(a); }
var b=4;
var c=f("b", 5, b); // c becomes 5
... see?
Admin
I feel dirty reading this!
Admin
why don't he just make it
function hotKeyFired (params....)
{
var id = null;
}
There, a variable that goes out of scope with value null in just one line.