| « Prev | Page 1 | Page 2 | Next » |
|
What The Failure does that code do?
Oh and second!!!1|!!!11 ;P (Bugger could'v been fR1st) ehehe |
|
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.
|
|
postComment( postComment( postComment( postComment( postComment("WTF",0),0),FILE_NOT_FOUND),1),0);
First, since I deny the existence of the above comments. |
|
Oh god, I'm getting flashbacks of LISP...
|
|
Whenever you see code like that, it screams out for some kind of loop.
Maybe he optimized with -funrolloops |
Re: A Bit of Closure
2008-07-28 08:41
•
by
Spellman
(unregistered)
|
So you're writing a macro and casting your spells then? |
|
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. |
loadingStage1, loadingStage2, ... It would look way better to have the code spread out in a sequence than to have it nested this way. So, I'm assuming you're being ironic. |
|
I not that familiar with the language but this code actually seems to execute backwards starting from the bottom and working upwards ...WTF?
|
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. |
Re: A Bit of Closure
2008-07-28 09:25
•
by
Lisper
(unregistered)
|
|
but this would be the code generated by macroexpand.
|
|
(forgot) and we would NEVER put a closing parenthesis on its own line.
|
Re: A Bit of Closure
2008-07-28 09:28
•
by
Waffle
(unregistered)
|
|
|
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.
|
|
In this case,
|
|
I think I get it ... this code was made in the USSR!
Because in Soviet Russia, code executes YOU!!!! |
Re: A Bit of Closure
2008-07-28 11:26
•
by
I walked the dinosaur
(unregistered)
|
...That's what she said..... |
Re: A Bit of Closure
2008-07-28 11:37
•
by
GetAway
(unregistered)
|
|
|
Reverse in code executing wrong with what is?
|
Re: A Bit of Closure
2008-07-28 12:01
•
by
Anonymous Cow-Herd
(unregistered)
|
outwards." and the starts the wrong "It's only when code in middle executes |
Yoda programming what it is! Too much have I said, my young padawan! |
Re: A Bit of Closure
2008-07-28 12:26
•
by
SomeCoder
(unregistered)
|
I want to write a YODA programming language compiler. Somebody come up with what YODA can stand for for the language :P |
|
Yet time, waste Of Development Another |
|
Ye Olde Development Anachronism
YODA Original Diagnostic Application Your Object Developing Appliance Yearly Optically Designing Applications |
Re: A Bit of Closure
2008-07-28 13:35
•
by
oncogenesis
(unregistered)
|
|
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.
|
Re: A Bit of Closure
2008-07-28 13:36
•
by
Madman1969
(unregistered)
|
|
Kill it with fire !
|
|
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. |
Re: A Bit of Closure
2008-07-28 14:28
•
by
Vlad Patryshev
(unregistered)
|
|
Forth called is language the
3 2 + . |
|
Re: A Bit of Closure
2008-07-28 15:45
•
by
zoips
(unregistered)
|
Looks more like Javascript to me, seeing as C# does not have a function keyword. |
|
YODA:
Another Development Of YODA |
|
|
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. =-) |
Not quite. The code you wrote is just one of the horrible things you get when you insist on not exiting a function early. That sort of thing is entirely possible in many languages. The article's problem seems to be that it's nesting closures inside closures inside closures inside... That's far messier, since it's got lots of added scope management thrown in for fun, making the code just that bit less performant or clear. At a technical level, it's a true WTF!? because it's not even wrong; the code's correct but still makes the person who encounters it in the wild want to take up a rusty spoon and do some damage to the perpetrator. The only thing missing really is the idiotic catch phrase for us to refer to this WTF by. Clbuttic indeedy. |
Re: A Bit of Closure
2008-07-28 17:53
•
by
Alex Papadimoluppoganeouficamulolulis
(unregistered)
|
|
PileOfMush is hereby banned from The Daily WTF. I'm sorry for that, everyone.
|
I like rust.
2008-07-28 17:56
•
by
Salad Fingers
(unregistered)
|
I'm here to enquire about your spoons... |
Oh man! And I didn't even include the Do Loop and the broader If that all of this crap was nested in. |
|
If LOAD_COMPLETE is a boolean value, it seems that it's assigned to FILE_NOT_FOUND.
|
Re: I like rust.
2008-07-28 23:46
•
by
Mr.'; Drop Database --
(unregistered)
|
Unfortunately, it's too big. |
|
If you print that out and hang it on a wall it looks like a babe.. seriously!
|
(defmacro delegate-chain (event actions) |
Re: I like rust.
2008-07-29 01:48
•
by
GermanGirl
(unregistered)
|
There is no spoon... |
|
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.
|
Re: A Bit of Closure
2008-07-29 04:46
•
by
Mouse
(unregistered)
|
The casing and the use of "function()" doesn't suggest that - your post suggests you dislike java and don't quite understand it. |
How about a fork? Anyway, at least he did the indentation... |
Re: A Bit of Closure
2008-07-29 09:09
•
by
leppie
(unregistered)
|
Pity you can only count to 6, if you knew more, you would have realized 7 comes after 6 and not 22. DOH! |
Re: A Bit of Closure
2008-07-29 10:42
•
by
35% Genius
(unregistered)
|
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. |
|
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. |
|
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
Log("Doing A");
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. |
| « Prev | Page 1 | Page 2 | Next » |