The Endless Loop



  • Was tracking down an error with one of our sprocs and ran into this bit of sql:


    while (@keeplooping = 1)
    begin
        /* help save us from an endless loop */
        select @stoplooking=@stoplooking+1
        if (@stoplooking > 30)
        begin
            print 'BREAKING ENDLESS LOOP IN [proc_DoStuff]'
            return
        end

        --do more stuff
    end


    So straight up looping in sql is frequently a good sign you are doing something wrong.  But having a condition where your loop never ends and deciding, "Well, just check if its looped 30 times and then kill it if it has" is just terrible in every way.



  • @Peraninth said:

    Was tracking down an error with one of our sprocs and ran into this bit of sql:


    while (@keeplooping = 1)
    begin
        /* help save us from an endless loop */
        select @stoplooking=@stoplooking+1
        if (@stoplooking > 30)
        begin
            print 'BREAKING ENDLESS LOOP IN [proc_DoStuff]'
            return
        end

        --do more stuff
    end


    So straight up looping in sql is frequently a good sign you are doing something wrong.  But having a condition where your loop never ends and deciding, "Well, just check if its looped 30 times and then kill it if it has" is just terrible in every way.

    I wonder where the number 30 comes from. Is it some clever reference to the -30- in journalism, is it some random number, or is there more to it?

    That's like opening a php.ini file and seeing that the maximum upload size has been set to 22MB, or opening a SSIS package and seeing that the MaximumErrorCount is set to 175. Reflecting on the meaning of those numbers is almost a zen experience.



  • @Ronald said:

    or opening a SSIS package and seeing that the MaximumErrorCount is set to 175.

    SpectateSwamp Information Search would never have a maximum of 175 errors! On Error Resume Next all the way, baby!


  • Considered Harmful

    @Ronald said:

    @Peraninth said:
    Was tracking down an error with one of our sprocs and ran into this bit of sql:


    while (@keeplooping = 1)
    begin
        /* help save us from an endless loop */
        select @stoplooking=@stoplooking+1
        if (@stoplooking > 30)
        begin
            print 'BREAKING ENDLESS LOOP IN [proc_DoStuff]'
            return
        end

        --do more stuff
    end


    So straight up looping in sql is frequently a good sign you are doing something wrong.  But having a condition where your loop never ends and deciding, "Well, just check if its looped 30 times and then kill it if it has" is just terrible in every way.

    I wonder where the number 30 comes from. Is it some clever reference to the -30- in journalism, is it some random number, or is there more to it?

    That's like opening a php.ini file and seeing that the maximum upload size has been set to 22MB, or opening a SSIS package and seeing that the MaximumErrorCount is set to 175. Reflecting on the meaning of those numbers is almost a zen experience.

    Choosing the right size for a varchar column always feels kind of dicey. Nvarchar(20) or nvarchar(100) for a name? Fuck it, nvarchar(max) so they can have gigabytes of characters. It's arbitrary anyway.


  • Filed under: Who needs any other datatype?

    You might laugh, but some people take this seriously. Sure, it might be a beginners' language not designed with performance in mind, but arrays as strings... fuck.



  • @Peraninth said:

    But having a condition where your loop never ends and deciding, "Well, just check if its looped 30 times and then kill it if it has" is just terrible in every way.

    I recall doing something like this once. I was supposed to trace the edges of an object in an image, and the algorithm will sometimes throw himself into an infinite loop if the picture wasn't quite right (probably a bug in my implementation, but i don't know even today). So if it went through a ton of pixels and still hasn't finished, it just gave up and tried again with a different filter to the image.



  • I like writing endless loops as

    for (; ;) {...}

    because the crying smiley reminds me it's wrong, so I only do it when I really have to



  • @Maciejasjmj said:

    Filed under: Who needs any other datatype?

    You might laugh, but some people take this seriously. Sure, it might be a beginners' language not designed with performance in mind, but arrays as strings... fuck.

    TCL takes this even further: in this piece of code:


    if $foo {
       puts "Hello!"
    }
    




    The if is actually a command that gets called with one argument: "$foo { puts "Hello!" }"; it then splits that into two pieces, and executes the second if appropriate. Why yes, executing strings is of course a fundamental part of the language :)





  •  @jpa said:

    @Maciejasjmj said:
    Filed under: Who needs any other datatype?

    You might laugh, but some people take this seriously. Sure, it might be a beginners' language not designed with performance in mind, but arrays as strings... fuck.

    TCL takes this even further: in this piece of code:


    if $foo {
       puts "Hello!"
    }
    




    The if is actually a command that gets called with one argument: "$foo { puts "Hello!" }"; it then splits that into two pieces, and executes the second if appropriate. Why yes, executing strings is of course a fundamental part of the language :)



    Now, you're being unfair and incorrect. Actually, if is called with two arguments - the value of the variable foo and the string “puts "Hello!"”. It's really very .. er.. I forget the word - if is basically a C macro that operates on plain strings and can be recursive! I think it's called atrocious? Or maybe urghlic. I think I've seen people call the way while works AAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaa.

     



  • @Mo6eB said:

    I like writing endless loops as

    for (; ;) {...}

    because the crying smiley reminds me it's wrong, so I only do it when I really have to


    That is the first argument for infinite for-loops that I've actually liked. Usually infinite for-loops make me want to punch kittens.


  • ♿ (Parody)

    @mikeTheLiar said:

    @Mo6eB said:

    I like writing endless loops as

    for (; ;) {...}

    because the crying smiley reminds me it's wrong, so I only do it when I really have to


    That is the first argument for infinite for-loops that I've actually liked. Usually infinite for-loops make me want to punch kittens.

    I have to disagree. The "crying smiley" looks more like an elephant to me. I think elephants are pretty cool, so this sends the wrong message. You should write your infinite loops the way God intended:

    	_10:
    	puts("Hello, World");
    	goto _10;
    


  • @boomzilla said:

    @mikeTheLiar said:
    @Mo6eB said:

    I like writing endless loops as

    for (; ;) {...}

    because the crying smiley reminds me it's wrong, so I only do it when I really have to

    That is the first argument for infinite for-loops that I've actually liked. Usually infinite for-loops make me want to punch kittens.

    I have to disagree. The "crying smiley" looks more like an elephant to me. I think elephants are pretty cool, so this sends the wrong message. You should write your infinite loops the way God intended:

    	_10:
    	puts("Hello, World");
    	goto _10;
    

     

    But then I can't use local scoping for variables! Like so:

    for (Iterator<Map.Entry<String, List<String>>> i = myMap.entrySet().iterator(); ;) {
        ... stuff ...
    } 

    Also, how do you break out of the loop early? You'll need another label. And it doesn't work in Java.



  • @boomzilla said:

    The "crying smiley" looks more like an elephant to me.
     

    I get the ears and tusks and all, but where's the trunk?


  • Discourse touched me in a no-no place

    @Mo6eB said:

    for (Iterator<Map.Entry<String, List<String>>> i = myMap.entrySet().iterator(); ;) {
    ... stuff ...
    }

    Apropos of nothing - I'm sure, as presented, that won't work (or compile) as intended....


  • ♿ (Parody)

    @dhromed said:

    @boomzilla said:
    The "crying smiley" looks more like an elephant to me.

    I get the ears and tusks and all, but where's the trunk?

    It's implied by the negative space between the two semicolons.


  • Considered Harmful

    @boomzilla said:

    @dhromed said:
    @boomzilla said:
    The "crying smiley" looks more like an elephant to me.

    I get the ears and tusks and all, but where's the trunk?

    It's implied by the negative space between the two semicolons.














    I am deeply offended by the negative space below your post.



  • @PJH said:

    @Mo6eB said:

     

    for (Iterator<Map.Entry<String, List<String>>> i = myMap.entrySet().iterator(); ;) {
        ... stuff ...
    } 

     

    Apropos of nothing - I'm sure, as presented, that won't work (or compile) as intended....
     

    You do need a liiiitle bit of boilerplate around it, sure:

    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Map.Entry;
    import java.util.Random;



    public class Scratch {

        public static void main(String[] args) {
            Map<String, List<String>> myMap = new HashMap<>();
            myMap.put("an key", Arrays.asList("one", "two", "three"));
            myMap.put("look i am a string", Arrays.asList("ichi", "ni", "san"));
            myMap.put(" ", Arrays.asList("this key intentionally left blank".split(" ")));
            myMap.put("not null", Arrays.<String>asList(null, null, null, null, null, null));

            Random rand = new Random();

            for (Iterator<Map.Entry<String, List<String>>> i = myMap.entrySet().iterator(); ;) {
                if (rand.nextFloat() < 0.1) {
                    System.out.println("Random exit!");
                    break;
                }
                if (!i.hasNext()) {
                    System.out.println("No more next!");
                    break;
                }
                Entry<String, List<String>> next = i.next();
                System.out.println("``" + next.getKey() + "'' = " + next.getValue());
            }
        }

    }
     

     

     


  • Discourse touched me in a no-no place

    @Mo6eB said:

    import java.util.Arrays;
    Ah - my error - I mistook it for C++...



  • @Ronald said:

    I wonder where the number 30 comes from. Is it some clever reference to the -30- in journalism

    What's -30- in journalism?



  • @veggen said:

    @Ronald said:
    I wonder where the number 30 comes from. Is it some clever reference to the -30- in journalism
    What's -30- in journalism?
    Back in the day stories were hand-written on pieces of paper, "-30-" indicated the end of the story. Why "-30-"? I don't know.



  • @HardwareGeek said:

    @veggen said:

    @Ronald said:
    I wonder where the number 30 comes from. Is it some clever reference to the -30- in journalism

    What's -30- in journalism?
    Back in the day stories were hand-written on pieces of paper, "-30-" indicated the end of the story. Why "-30-"? I don't know.

    Wikipedia mentions two interpretations but the one I've heard most often is that back in the days where people were submitting hand-written documents they were using "X" to indicate stops (X = end of sentence, XX = end of paragraph, XXX = end of article). So 30 would be a clever translation from the roman numeral XXX.

    That's an unfortunate choice. How wonderful would that be if journalists were to finish their article with a pornographic image to replace the XXX. Maybe an ASCII goatse or something more tasteful.

          @@@@@
         @@. .@@
        @@@\=/@@@
        @.-- --.@
        /(.) (.)\
        \ ) . ( /
        '(  v  )`
          \ | /
          ( | )
          '- -`
    


  • @Ronald said:

    How wonderful would that be if journalists were to finish their article with a pornographic image to replace the XXX
    There you have the explanation of how p0rn came to be referered to as "X Rated".



  • @Ronald said:

    Wikipedia mentions two interpretations but the one I've heard most often is that back in the days where people were submitting hand-written documents they were using "X" to indicate stops (X = end of sentence, XX = end of paragraph, XXX = end of article). So 30 would be a clever translation from the roman numeral XXX.
    Interesting. Back when I worked on the school newspaper in high school, we were simply told to write -30- at the end of our stories; I don't remember being given any explanation. However, as an Amateur Radio operator, the explanation based on the telegraphic code seems to me much more likely (if less, um... creative).

     



  • @Ronald said:

          @@@@@
    @@. .@@
    @@@=/@@@
    @.-- --.@
    /(.) (.)
    \ ) . ( /
    '( v ) \ | / ( | ) '- -

    Not sure about the Cyber(wo)man head ...



  • @El_Heffe said:

    @Ronald said:

    How wonderful would that be if journalists were to finish their article with a pornographic image to replace the XXX
    There you have the explanation of how p0rn came to be referered to as "X Rated".


    Note to self: 10 year olds can watch porn



  • @HardwareGeek said:

    Amateur Radio operator

    Roger That!

    Bonus question: how many pairs of gloves would you wear if you had to touch that arm rest (or that seat belt)?



  • @Ronald said:

    @HardwareGeek said:
    Amateur Radio operator

    Roger That!

    Bonus question: how many pairs of gloves would you wear if you had to touch that arm rest (or that seat belt)?

     

    I would build a remotely-operated robotic arm. And put 8 pairs of gloves on it. It will also have an embedded flamethrower.

     


Log in to reply