- 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
What The Failure does that code do?
Oh and second!!!1|!!!11 ;P (Bugger could'v been fR1st) ehehe
Admin
No, it wasn't your UI developer who left, it was some incompetent twit that had been let loose on your UI code who left.
Admin
postComment( postComment( postComment( postComment( postComment("WTF",0),0),FILE_NOT_FOUND),1),0);
First, since I deny the existence of the above comments.
Admin
Oh god, I'm getting flashbacks of LISP...
Admin
Whenever you see code like that, it screams out for some kind of loop.
Maybe he optimized with -funrolloops
Admin
Admin
Thank god for anonymous functions - imagine if one would have to think names for god knows how many functions to achieve the same functionality. But since I'm not familiar with Scheme, I have no idea what the wtf is.
Admin
Admin
I not that familiar with the language but this code actually seems to execute backwards starting from the bottom and working upwards ...WTF?
Admin
If you wrote LISP code like this.. you're the WTF. The beauty of LISP and SCHEME is that while what is going on behind the scenes may look like this, your code doesn't have to.
Admin
but this would be the code generated by macroexpand.
Admin
(forgot) and we would NEVER put a closing parenthesis on its own line.
Admin
Admin
Twenty-two levels of nesting (plus the usual noise around this). That's about twenty too many for this code to be easily understandable. And a net effect of the code "executing in reverse" too. At least we know why the author left: he was faced with maintaining this monstrosity.
Admin
In this case,
Admin
I think I get it ... this code was made in the USSR!
Because in Soviet Russia, code executes YOU!!!!
Admin
...That's what she said.....
Admin
Admin
Reverse in code executing wrong with what is?
Admin
outwards." and the starts the wrong "It's only when code in middle executes
Admin
Admin
I want to write a YODA programming language compiler. Somebody come up with what YODA can stand for for the language :P
Admin
Admin
Yet time, waste Of Development Another
Admin
Ye Olde Development Anachronism YODA Original Diagnostic Application Your Object Developing Appliance Yearly Optically Designing Applications
Admin
As the cliche says, you can write bad code in any language. Also, any sufficiently complicated C or Fortran (or C# per this example) program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
Admin
Kill it with fire !
Admin
A neat way to define a state machine. What we are having here is not a closure, but a continuation. I am sure it can be done easier using, say, some kind of combinator.
Admin
Forth called is language the
3 2 + .
Admin
Admin
Looks more like Javascript to me, seeing as C# does not have a function keyword.
Admin
YODA:
Another Development Of YODA
Admin
Admin
I have some 7 year old failcode that looks just like that, but in VB. Ah, the memories.
EDIT BTW, I've been told it's still running. =-)
Admin
The only thing missing really is the idiotic catch phrase for us to refer to this WTF by. Clbuttic indeedy.
Admin
PileOfMush is hereby banned from The Daily WTF. I'm sorry for that, everyone.
Admin
Admin
Oh man! And I didn't even include the Do Loop and the broader If that all of this crap was nested in.
Admin
If LOAD_COMPLETE is a boolean value, it seems that it's assigned to FILE_NOT_FOUND.
Admin
Admin
If you print that out and hang it on a wall it looks like a babe.. seriously!
Admin
Admin
There is no spoon...
Admin
I count 6 levels of nesting, not 22. The code isn't bad after some pretty-printing is applied. It looks like someone who has but one or two tendons left to chew before escaping from the mental trap that is Java.
Admin
The casing and the use of "function()" doesn't suggest that - your post suggests you dislike java and don't quite understand it.
Admin
How about a fork?
Anyway, at least he did the indentation...
Admin
Pity you can only count to 6, if you knew more, you would have realized 7 comes after 6 and not 22. DOH!
Admin
The code until PopupDisablePanel.hidePopup() has 28 opening parenthesis and braces and 6 closing parenthesis. That is 22 levels of nesting. However, you did prove that there are people who can't count.
Admin
There is no need to reach for your macro hammer just for this case.
function addLoadCompleteDelegates(eventManager, delegates) { eventManager.addDelegate(LOAD_COMPLETE, new FunctionDelegate( function() { addLoadCompleteDelegates(eventManager, tail(delegates)); head(delegates)(); } }
addLoadCompleteDelegates(eventManager, [ loadExistingUserMacData, loadStatusGroupData, function () { if (macAddress.length > 0) { PopupDisablePanel.setPopupText(Loading Config Data..."); loadConfigData(); } else { checkCreateConfigValid(); PopupDisablePanel.setPopupText("Loading User Data..."); loadUserData(); }
},
... ]);
Assuming I am understanding this right of course.
Admin
Wow, I can't believe it sat this long and nobody actually got what the code does. The nesting is a function that defines a function that defines a function... etc., not a for-loop or anything else like that. The whole point is that it's defining event handlers for asynchronous (probably UI) code. It's not readable, so that's a WTF, but it's a reasonably elegant way to handwave out some stuff you don't want to have to break into ~6-8 separate named functions. If you tried to write it procedurally, because of the multithreading issues it would have to be something like
which would have to run in a thread separate from the UI thread (which could have run the messy-but-functional code from the original post just fine).
While the above is more compact and readable, the "Best Practice" is to use delegates instead, so that the OS message pump can handle firing off code instead of leaving the. It's kind-of-mostly more elegant to simply register event handlers than to do polling/monitoring manually. They just didn't structure the event handler definitions as well as they might have.