• Qvasi (unregistered)

    What The Failure does that code do?

    Oh and second!!!1|!!!11 ;P (Bugger could'v been fR1st) ehehe

  • (cs)

    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.

  • Anonymous Cow-Herd (unregistered)

    postComment( postComment( postComment( postComment( postComment("WTF",0),0),FILE_NOT_FOUND),1),0);

    First, since I deny the existence of the above comments.

  • (cs)

    Oh god, I'm getting flashbacks of LISP...

  • (cs)

    Whenever you see code like that, it screams out for some kind of loop.

    Maybe he optimized with -funrolloops

  • Spellman (unregistered) in reply to Volmarias
    Volmarias:
    Oh god, I'm getting flashbacks of LISP...
    So you're writing a macro and casting your spells then?
  • Azeroth (unregistered)

    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.

  • (cs) in reply to Azeroth
    Azeroth:
    Thank god for anonymous functions - imagine if one would have to think names for god knows how many functions to achieve the same functionality.
    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.
  • ex-Pizza delivery man (unregistered)

    I not that familiar with the language but this code actually seems to execute backwards starting from the bottom and working upwards ...WTF?

  • (cs) in reply to Volmarias
    Volmarias:
    Oh god, I'm getting flashbacks of LISP...

    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.

  • Lisper (unregistered) in reply to Volmarias

    but this would be the code generated by macroexpand.

  • Lisper (unregistered)

    (forgot) and we would NEVER put a closing parenthesis on its own line.

  • Waffle (unregistered) in reply to Lisper
    Looks
    perfectly
    fine
    to
    me
  • (cs)

    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.

  • (cs) in reply to Waffle

    In this case,

    me
    to
    fine
    perfectly
    Looks
  • (cs)

    I think I get it ... this code was made in the USSR!

    Because in Soviet Russia, code executes YOU!!!!

  • I walked the dinosaur (unregistered) in reply to danixdefcon5
    danixdefcon5:
    I think I get it ... this code was made in the USSR!

    Because in Soviet Russia, code executes YOU!!!!

    ...That's what she said.....

  • GetAway (unregistered) in reply to Waffle
    Waffle:
    Looks
    perfectly
    fine
    to
    me
    I agree! Lol
  • pfm (unregistered) in reply to dkf

    Reverse in code executing wrong with what is?

  • Anonymous Cow-Herd (unregistered) in reply to pfm
    pfm:
    Reverse in code executing wrong with what is?

    outwards." and the starts the wrong "It's only when code in middle executes

  • (cs) in reply to pfm
    pfm:
    Reverse in code executing wrong with what is?
    Yoda programming what it is! Too much have I said, my young padawan!
  • SomeCoder (unregistered) in reply to danixdefcon5
    danixdefcon5:
    pfm:
    Reverse in code executing wrong with what is?
    Yoda programming what it is! Too much have I said, my young padawan!

    I want to write a YODA programming language compiler. Somebody come up with what YODA can stand for for the language :P

  • sn (unregistered)
    PopupDisablePanel.setPopupText(Loading Config Data...");
                                   ^ syntax error ;-P
    
  • (cs) in reply to SomeCoder
    SomeCoder:
    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

  • (cs)

    Ye Olde Development Anachronism YODA Original Diagnostic Application Your Object Developing Appliance Yearly Optically Designing Applications

  • oncogenesis (unregistered) in reply to Volmarias

    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.

  • Madman1969 (unregistered) in reply to dkf

    Kill it with fire !

  • Vlad Patryshev (unregistered)

    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.

  • Vlad Patryshev (unregistered) in reply to fruey

    Forth called is language the

    3 2 + .

  • AdT (unregistered)
    eventManager.addDelegate(ARTICLE_COMPLETE,
      d1 = new FunctionDelegate(
        function() {
          if (article.type == MFD)
             mfd = 1, eventManager.addDelegate(ARTICLE_COMPLETE,
               d2 = new FunctionDelegate(
                 function() {
                   if (article.type == SOD)
                   {
                     say("Finally, a CodeSOD again after " + mfd
                       + " MFDs.");
                     eventManager.addDelegate(ARTICLE_COMPLETE, d1);
                   }
                   else
                     article.type == MFD && ++mfd,
                     eventManager.addDelegate(ARTICLE_COMPLETE, d2);
                 }
               )
             );
           else
             eventManager.addDelegate(ARTICLE_COMPLETE, d1);
        }
      )
    );
    
  • zoips (unregistered) in reply to oncogenesis
    oncogenesis:
    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.

    Looks more like Javascript to me, seeing as C# does not have a function keyword.

  • pfm (unregistered)

    YODA:

    Another Development Of YODA

  • wesley0042 (unregistered)
    This code makes me sad    };
                        };
                  };
             };
        };
    
  • (cs)

    I have some 7 year old failcode that looks just like that, but in VB. Ah, the memories.

          If Not PageIsSepSheet And Not PageIsBlank Then
            If Not PageIsMissingDVF Then
              DvfIsGood = ReadDVF(TMID)
              If DvfIsGood Then
                If Not PageIsMissingTIF Then
                  If Not PageIsRemoved Then
                    If PageIsGood Then
    'WRITE LOG, IPT, & DOC.LST '''''
                      WriteToLists ' <- You waded thru all that to get to this
    ''''''''''''''''''''''''''''''''
                      If Verify(1) = "49" Then  'WRITE WARNING TO ERROR LOG
                        ErrorMsg = ErrorMsg & "Page with status 49 ('SCANNED OK') imported." & vbNewLine
                        AppendLog ErrorLogPath, ErrorLogName, ErrorMsg
                      End If
                    Else  'WRITE TO ERROR LOG / PageIsGood = False
                      ErrorMsg = ErrorMsg & "Page status " & Verify(1) & " not processed." & vbNewLine
                      AppendLog ErrorLogPath, ErrorLogName, ErrorMsg
                    End If
                  Else  'WRITE TO ERROR LOG / PageIsRemoved = True
                    ErrorMsg = ErrorMsg & "Page marked as REMOVED." & vbNewLine
                    AppendLog ErrorLogPath, ErrorLogName, ErrorMsg
                  End If
                Else  'WRITE TO ERROR LOG / PageIsMissingTIF = True
                  ErrorMsg = ErrorMsg & "Page was missing TIF file." & vbNewLine
                  AppendLog ErrorLogPath, ErrorLogName, ErrorMsg
                End If
              Else  'WRITE TO ERROR LOG / DVFIsGood = False
                ErrorMsg = ErrorMsg & "Could not interpret DVF file." & vbNewLine
                AppendLog ErrorLogPath, ErrorLogName, ErrorMsg
              End If
            Else  'WRITE TO ERROR LOG / PageIsMissingDVF = True
              If PageIsRemoved Then
                ErrorMsg = ErrorMsg & "Page marked as REMOVED." & vbNewLine
              Else
                ErrorMsg = ErrorMsg & "Could not find DVF file." & vbNewLine
              End If
              AppendLog ErrorLogPath, ErrorLogName, ErrorMsg
            End If
          Else  'Do not log SEPSHEETs
          End If
    

    EDIT BTW, I've been told it's still running. =-)

  • (cs) in reply to PileOfMush
    PileOfMush:
    I have some 7 year old failcode that looks just like that, but in VB.
    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.

  • Alex Papadimoluppoganeouficamulolulis (unregistered) in reply to PileOfMush

    PileOfMush is hereby banned from The Daily WTF. I'm sorry for that, everyone.

  • Salad Fingers (unregistered) in reply to dkf
    dkf:
    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.
    I'm here to enquire about your spoons...
  • (cs) in reply to Alex Papadimoluppoganeouficamulolulis
    Alex Papadimoluppoganeouficamulolulis:
    PileOfMush is hereby banned from The Daily WTF. I'm sorry for that, everyone.

    Oh man! And I didn't even include the Do Loop and the broader If that all of this crap was nested in.

  • Anonymouse (unregistered)

    If LOAD_COMPLETE is a boolean value, it seems that it's assigned to FILE_NOT_FOUND.

  • Mr.'; Drop Database -- (unregistered) in reply to Salad Fingers
    Salad Fingers:
    dkf:
    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.
    I'm here to enquire about your spoons...
    Unfortunately, it's too big.
  • Tourist (unregistered)

    If you print that out and hang it on a wall it looks like a babe.. seriously!

  • chkno (unregistered)
    (defmacro delegate-chain (event actions)
      (when (consp actions)
        `(add-delegate ,event (lambda ()
           (delegate-chain ,event ,(rest actions))
           ,(first actions)))))
    
    (delegate-chain 'load-complete
      ((load-existing-user-mac-data)
       (load-status-group-data)
       ...))
  • GermanGirl (unregistered) in reply to Salad Fingers
    Salad Fingers:
    dkf:
    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.
    I'm here to enquire about your spoons...

    There is no spoon...

  • Anonymous (unregistered)

    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.

  • Mouse (unregistered) in reply to Anonymous
    Anonymous:
    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.

    The casing and the use of "function()" doesn't suggest that - your post suggests you dislike java and don't quite understand it.

  • unknown (unregistered) in reply to GermanGirl
    GermanGirl:
    Salad Fingers:
    dkf:
    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.
    I'm here to enquire about your spoons...

    There is no spoon...

    How about a fork?

    Anyway, at least he did the indentation...

  • leppie (unregistered) in reply to dkf
    dkf:
    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.

    Pity you can only count to 6, if you knew more, you would have realized 7 comes after 6 and not 22. DOH!

  • 35% Genius (unregistered) in reply to leppie
    leppie:
    dkf:
    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.

    Pity you can only count to 6, if you knew more, you would have realized 7 comes after 6 and not 22. DOH!

    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.

  • Asd (unregistered)

    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.

  • James (unregistered)

    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");
    start(DoA());
    waitfor(DoAComplete);
    
    Log("Doing B");
    start(DoB());
    waitfor(DoBComplete);
    
    ...

    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.

Leave a comment on “A Bit of Closure”

Log In or post as a guest

Replying to comment #:

« Return to Article