• Asd (unregistered)

    James: If you actually read the comments before yours you would see that most of us do understand the code. My comment illustrates how to implement the required functionality much more concisely in plain javascript. The solution is to accept a list of functions to handle the completion events, and create a new function which registers the next one before handling the current event.

  • pubbing (unregistered)

    Recursion???????

  • pubbing (unregistered)

    Recursion???????

  • (cs) in reply to PileOfMush
    PileOfMush:
    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. =-)

    You mean it hasn't even finished yet processing the If-Then construct?? Or is it still busy logging errors?

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

    Who cares if one can understand Java's insanity. It's sufficient to understand that Java's a WTF on it's own.

  • (cs) in reply to AdT
    AdT:
    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.");
    ...
    

    "Finally, a CodeSOD again after 1 MFDs"

  • (cs)

    Looks like nobody here can spot the language, it is ActionScript version 2, you know, the Flash one.

  • sheyll (unregistered) in reply to dkf

    I have written code like that myself, and although it is stupid and contains a lot of noise, it has some positive aspects to it. I.e. one will immediately recognize the pattern! It is very very simple to look at it, and to instantly know what's going on.

    But I evolved. Today I wouldn't write something like this in CPS, so that one doesn't need to read this backwards. One could imagine a higher order function, that chains these actions togehter, nad which evaluates i.e. the return value of these functions the figure out, if an error occured.

Leave a comment on “A Bit of Closure”

Log In or post as a guest

Replying to comment #:

« Return to Article