Plan B = try Plan A again



  • I work with a system that has a curious behavior of not always allowing people to logon the first time they try, but if they keep trying at some point it works. There is possibly a DCOM problem somewhere in the pipe and this has been "actively" investigated by the vendor for as long as I remember.

    Meanwhile this led me to create a superb piece of code:

     int tentatives = 10;

     do
     {
      try
      {
       OpenSession();
       success = true;
      }
      catch (Exception)
      {
       success = false;
       tentatives--;
      }
     }
     while (!success && 0 < tentatives);

    The fun part is that in the real code, the "tentatives" initial value is loaded from a script that counts the number of tickets open for "connection failed" incidents, so this could qualify as a self-healing environment.

     

     



  • @thistooshallpass said:

    the "tentatives" initial value is loaded from a script that counts the number of tickets open for "connection failed" incidents
    This part made me feel compelled to give this post stars, for some reason.



  • What's wrong with a for loop?

    for (int attempt = 0; attempt < 10; attempt++) {
        try {
            OpenSession();
            break;
        }
        catch {
            // Swallow exception and go round again
        }
    }


  • That's just precious.



  • @thistooshallpass said:

    The fun part is that in the real code, the "tentatives" initial value is loaded from a script that counts the number of tickets open for "connection failed" incidents, so this could qualify as a self-healing environment.

    I... I like this idea... This inspires me. I think I can incorporate this "self-healing" into some of my own scripts... :D



  • @Zecc said:

    @thistooshallpass said:

    the "tentatives" initial value is loaded from a script that counts the number of tickets open for "connection failed" incidents
    This part made me feel compelled to give this post stars, for some reason.

    Agreed!



  • That is simply the most beautiful workaround I have ever seen in my entire life.

    But what if the machine gets phisically disconnected from the network? I'd suggest having two catches, one for network faults, another NeverGonnaGiveYouUpException for failed tickets.



  • [quote user="Renan "C#" Sousa"]

    That is simply the most beautiful workaround I have ever seen in my entire life.

    But what if the machine gets phisically disconnected from the network? I'd suggest having two catches, one for network faults, another NeverGonnaGiveYouUpException for failed tickets.

    [/quote] 

    What about NeverGonnaLetYouDownException? Gotta handle those!

     



  • Obligatory "never gonna say goodbye" exception post.

     



  • @RichP said:

    Obligatory "never gonna say goodbye" exception post.

     

    You missed a couple exceptions in between:

    • NeverGonnaRunAroundAndDesertYouException
    • NeverGonnaMakeYouCryException

    And finally, to follow up with the NeverGonnaTellALieAndHurtYouException.



  • could be worse...I wrote this yesterday:

            retryIndex:
            try
            {
                document = web.Load((String)e.Argument);
            }
            catch
            {
                goto retryIndex;
            }
    

    the server i'm connecting to has some random 503 errors, and if it's really overloaded i just get 404's



  • Goto summons velociraptors.

     


  • Trolleybus Mechanic

     I've done a retry loop like that, usually around an HttpWebRequest, since they occasionally flake out.

    Hooking it up to the ticketing system-- that shit's the level of awsome that gets passed around by textfile on usenet.



  • @hoodaticus said:

    Goto summons velociraptors.
     

    PHP introduced  the Goto keyword in a recent version (5.3).

    I found out because someone (not me) had defined a function called Goto(), which of course broke on upgrade.

    All together now ...

     

     



  • Hi Mods,

    hoodaticus included an XKCD comic into the thread (see above).

     

    Please delete this troll thread.

    Thanks


     


  • ♿ (Parody)

    @Helix said:

    Please delete this troll thread.

    But all threads are troll threads. Nihilist.



  • @boomzilla said:

    @Helix said:
    Please delete this troll thread.
    But all threads are troll threads. Nihilist.
     

    Suggest mods to run "format c: /y"



  • @token_woman said:

    All together now ...
     

    "RTFchangelog BEFORE you upgrade!"

    ...is that not what you were prompting us for?

     


  • Trolleybus Mechanic

    @token_woman said:

    @hoodaticus said:

    Goto summons velociraptors.
     

    PHP introduced  the Goto keyword in a recent version (5.3).

    I found out because someone (not me) had defined a function called Goto(), which of course broke on upgrade.

    All together now ...

     

    We are the boys!



  • @token_woman said:

    @hoodaticus said:

    Goto summons velociraptors.
     

    PHP introduced  the Goto keyword in a recent version (5.3).

    I found out because someone (not me) had defined a function called Goto(), which of course broke on upgrade.

    All together now ...

     

     

    Reminds me of the IF function in Excel: if(condition,value_for_true,value_for_false)



    The IIF function in MSFT Reporting Services has the same signature, but it leads to more creative code because all parameters are evaluated before returning a value:

    
    AverageScore = IIF(ItemCount>0, Total/ItemCount, 0)  //will cause a DivByZero error if ItemCount==0
    AverageScore = IIF(ItemCount>0, Total/ IIF(ItemCount>0,ItemCount,911), 0)  //this will work, and you get to choose whatever number for the dummy divide!
    


    Lots of fun!


  • @Rootbeer said:

    @token_woman said:

    All together now ...
     

    "RTFchangelog BEFORE you upgrade!"

     

     

    You have time?



  • @token_woman said:

    @hoodaticus said:

    Goto summons velociraptors.
     

    PHP introduced  the Goto keyword in a recent version (5.3).

    I found out because someone (not me) had defined a function called Goto(), which of course broke on upgrade.

    All together now ...

     

     

    If I could give posts stars …



  • @token_woman said:

    PHP introduced  the Goto keyword in a recent version (5.3).

    You're kidding me! I could'a sworn I used goto all over the place (but only where it really made sense) in my last PHP product, under 5.2.



  • @Who_the_Fuck said:

    @token_woman said:
    PHP introduced  the Goto keyword in a recent version (5.3).

    You're kidding me! I could'a sworn I used goto all over the place (but only where it really made sense) in my last PHP product, under 5.2.

     

     

    ses 'ere it's 5.3.

    http://php.net/manual/en/control-structures.goto.php

    Funnily enough they've repoduced the xkcd velociraptor cartoon on that page - self deprecating bastards got there before me :)



  • @token_woman said:

    @Who_the_Fuck said:

    @token_woman said:
    PHP introduced  the Goto keyword in a recent version (5.3).

    You're kidding me! I could'a sworn I used goto all over the place (but only where it really made sense) in my last PHP product, under 5.2.

     

     

    ses 'ere it's 5.3.

    http://php.net/manual/en/control-structures.goto.php

    Funnily enough they've repoduced the xkcd velociraptor cartoon on that page - self deprecating bastards got there before me :)

     

     

    Even including xkcd references they know it's a fudge feature.  Funny when language standards bow down to peer pressure and include features on demand, even when those features are known bad practice. 

     


  • Discourse touched me in a no-no place

    @Helix said:

    even when those features are known bad practice. 
    In general programmers' use of goto can lead to bad code, but as with all most generalisations, is not always true



  • @PJH said:

    is not always true
    Nice read. Thanks for the link.



  • @token_woman said:

    PHP introduced  the Goto keyword in a recent version (5.3).

    I found out because someone (not me) had defined a function called Goto(), which of course broke on upgrade.


    I know someone who did the same. And while he was a bit angry that his function broke, he was overjoyed that PHP FINALLY has the vital goto support!



  • @derula said:

    @token_woman said:

    PHP introduced  the Goto keyword in a recent version (5.3).

    I found out because someone (not me) had defined a function called Goto(), which of course broke on upgrade.


    I know someone who did the same. And while he was a bit angry that his function broke, he was overjoyed that PHP FINALLY has the vital goto support!

    These goto() functions, I presume that they're not WTF attempts to replace the goto keyword itself? (That would be awful)



  • @Daniel Beardsmore said:

    @derula said:
    @token_woman said:

    PHP introduced  the Goto keyword in a recent version (5.3).

    I found out because someone (not me) had defined a function called Goto(), which of course broke on upgrade.


    I know someone who did the same. And while he was a bit angry that his function broke, he was overjoyed that PHP FINALLY has the vital goto support!

    These goto() functions, I presume that they're not WTF attempts to replace the goto keyword itself? (That would be awful)

    Hm, I checked my chat history with that guy and it seems I got two things mixed up. There's that one guy who likes goto very much and who told me it's now in PHP, but then the person who had a goto() function that broke was someone else... and he wasn't a goto fan so I guess his goto() meant something different, but I can't be sure because he was on IRC where I didn't save logs.



  • @Zecc said:

    @PJH said:

    is not always true
    Nice read. Thanks for the link.

     

     

    +1. Really enjoyed it. 



  • @Daniel Beardsmore said:

    These goto() functions, I presume that they're not WTF attempts to replace the goto keyword itself? (That would be awful)
    The one I mentioned is in an API for controlling a system I'll call X, and the goto() function is there to mirror the goto() function in X's own language. This language is peppered with goto functions of various stripes, and inherits the worst features of goto-ey languages, having the power of BASIC combined with the readability of machine code.The system it controls is no great shakes either - but it is open source so yay!



  • @token_woman said:

    @Daniel Beardsmore said:

    These goto() functions, I presume that they're not WTF attempts to replace the goto keyword itself? (That would be awful)
    The one I mentioned is in an API for controlling a system I'll call X, and the goto() function is there to mirror the goto() function in X's own language. This language is peppered with goto functions of various stripes, and inherits the worst features of goto-ey languages, having the power of BASIC combined with the readability of machine code.The system it controls is no great shakes either - but it is open source so yay!

    <Picard>Tell me more!</Picard>



  • @Daniel Beardsmore said:

    <Picard>Tell me more!</Picard>
    Too paranoid to deobfuscate right now, but it's coming. For now let's just say X is, well, a bit of a wildcard.



  • @token_woman said:

    Too paranoid to deobfuscate right now, but it's coming. For now let's just say X is, well, a bit of a wildcard.

    Telephony?


Log in to reply