You have to try to do nothing with so much code.



  • This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    Try
    

    Catch ex As Exception
    Throw ex

    Finally

    End Try



  • Try

    Catch ex As SpontaneousException
    Throw ex

    Finally

    End Try



  • SpontaneousException made me crack out lout in the office.



  • @djork said:

    This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    Try
    

    Catch ex As Exception
    Throw ex

    Finally

    End Try

    So... the WTF is that they didn’t just re-throw with “Throw”, right?



  • @Random832 said:

    @djork said:

    This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    TryCatch ex As Exception    Throw exFinallyEnd Try

    So... the WTF is that they didn’t just re-throw with “Throw”, right?

     

    How about the fact there is NO code inside the Try block? 



  • @MasterPlanSoftware said:

    @Random832 said:
    @djork said:

    This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    TryCatch ex As Exception    Throw exFinallyEnd Try

    So... the WTF is that they didn’t just re-throw with “Throw”, right?

    How about the fact there is NO code inside the Try block?


  • Winner of the 2016 Presidential Election

    @Random832 said:

    @djork said:

    This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    Try

    Catch ex As Exception
    Throw ex

    Finally

    End Try

    So... the WTF is that they didn’t just re-throw with “Throw”, right?

    No, the WTF is that it's in VB.</obligatory>

    Actually, I've seen this many times in boilerplate templates, which assume you are going to write something inside the try block.  So, actually, yes; the most WTF part is that they don't re-throw properly.



  • @joe.edwards@imaginuity.com said:

    @Random832 said:
    @djork said:

    This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    Try

    Catch ex As Exception
    Throw ex

    Finally

    End Try

    So... the WTF is that they didn’t just re-throw with “Throw”, right?

    No, the WTF is that it's in VB.</obligatory>

    Actually, I've seen this many times in boilerplate templates, which assume you are going to write something inside the try block.  So, actually, yes; the most WTF part is that they don't re-throw properly.

    I agree. Looks like somebody just inserted a snippet on Visual Studio meaning to do something there, then forgot to take it out.




  • I'm more surprised the 'whoosh' tag hasn't been used before. I was expecting as many posts as there are sidebar WTFs...



  • @djork said:

    This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    Try

    Catch ex As Exception
    Throw ex

    Finally

    End Try

     Widely-believed fact: In cases like this, the CLR inserts a "throw" instruction out of spite
     



  • Let's have a little contest:  Who can write the most code that will compile to no instructions?



  • @jcoehoorn said:

    Let's have a little contest:  Who can write the most code that will compile to no instructions?

    Excellent WTF coding challenge right there.  Comments don't count, and no repeating.  I think C might be a good place to start, with the help of GCC's optimization options. 



  • @MasterPlanSoftware said:

    @Random832 said:
    @djork said:

    This
    is actually, for real, totally serious, not joking, straight code from
    our production application. Absolutely nothing was changed in this
    snippet.

    TryCatch ex As Exception    Throw exFinallyEnd Try

    So... the WTF is that they didn’t just re-throw with “Throw”, right?

     

    How about the fact there is NO code inside the Try block?

    Are you implying it would be OK if there was also no code inside the Catch block?



  • @MasterPlanSoftware said:

    @Random832 said:
    @djork said:

    This
    is actually, for real, totally serious, not joking, straight code from
    our production application. Absolutely nothing was changed in this
    snippet.

    TryCatch ex As Exception    Throw exFinallyEnd Try

    So... the WTF is that they didn’t just re-throw with “Throw”, right?

     

    How about the fact there is NO code inside the Try block?

    But what if the no code inside the Try block was using an sNOP instead of a qNOP?

     



  • @DaveK said:

    @MasterPlanSoftware said:
    @Random832 said:
    @djork said:

    This
    is actually, for real, totally serious, not joking, straight code from
    our production application. Absolutely nothing was changed in this
    snippet.

    TryCatch ex As Exception    Throw exFinallyEnd Try

    So... the WTF is that they didn’t just re-throw with “Throw”, right?

     

    How about the fact there is NO code inside the Try block?

    Are you implying it would be OK if there was also no code inside the Catch block?

    Only if you subscribe to the "On Error Resume Next" pattern.

     



  • @djork said:

    This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    Try

    Catch ex As Exception
    Throw ex

    Finally

    End Try

    This is no big deal.  I use CodeRush and it stubs out a bunch of code for me.  If I'm rockin', like if I'm in the zone, I'll type "tc" and BAMB!  There is my try-catch-block all ready to go.  And sometimes I won't refactor as well as I should, and leave this stuff around.  That is, when I'm not unemployed.

    So I have say that this is not a WTF.  Nothing personal.



  • @TunnelRat said:

    @djork said:

    This is actually, for real, totally serious, not joking, straight code from our production application. Absolutely nothing was changed in this snippet.

    TryCatch ex As Exception    Throw exFinallyEnd Try

    This is no big deal.  I use CodeRush and it stubs out a bunch of code for me.  If I'm rockin', like if I'm in the zone, I'll type "tc" and BAMB!  There is my try-catch-block all ready to go.  And sometimes I won't refactor as well as I should, and leave this stuff around.  That is, when I'm not unemployed.

    So I have say that this is not a WTF.  Nothing personal.

    So you leave stubs that eliminate the stack during an exception all over your code?

     Brilliant!



  • @djork said:

    @jcoehoorn said:

    Let's have a little contest:  Who can write the most code that will compile to no instructions?

    Excellent WTF coding challenge right there.  Comments don't count, and no repeating.  I think C might be a good place to start, with the help of GCC's optimization options. 

    Wouldn't that be a rather easy challange?

    if (false) {
        // Insert arbitrary amounts of code here
    }
     



  • If that's the extent of the program, will the compiler allow it to compile to no instructions?

    Also, I'm sure there'd be some hideous means to get the code in such a block to execute. Don't know what mind. 



  • @m0ffx said:

    If that's the extent of the program, will the compiler allow it to compile to no instructions?

    I think so. At least the object files are of the same size....

    [erich@iTux ~]$ cat test1.c
    #include <stdio.h>
    int nix() {
            if (0) {
                    printf("Nix");
            }
    }
    [erich@iTux ~]$ cat test2.c
    #include <stdio.h>
    int nix() {
    }
    [erich@iTux ~]$ cc -c test1.c
    [erich@iTux ~]$ cc -c test2.c
    [erich@iTux ~]$ ls -l test1.o test2.o
    -rw-r--r-- 1 erich erich 685 Nov  4 13:35 test1.o
    -rw-r--r-- 1 erich erich 685 Nov  4 13:35 test2.o
    [erich@iTux ~]$


     



  • @m0ffx said:

    If that's the extent of the program, will the compiler allow it to compile to no instructions?

    Also, I'm sure there'd be some hideous means to get the code in such a block to execute. Don't know what mind. 

    At least SpiderMonkey, Mozilla's JS compiler/interpreter does it for JavaScript. Because it also includes a decompiler, it can easily be seen:

    function f() {
        if (0) {
           alert("foo");
        }
    }
    

    alert(f.toString());

    shows
    function f() {
    }
    


  • @m0ffx said:

    If that's the extent of the program, will the compiler allow it to compile to no instructions?

    Also, I'm sure there'd be some hideous means to get the code in such a block to execute. Don't know what mind. 

    if (0) {

       label: printf("oh noes!");

    }

    goto label;

     

    Since even "unreachable code"s compile into the object file (on my compiler anyway), we need something the optimizer would throw away. How about:

    int i;

    for(i=0; i<10; i++);

    for(i=0; i<10; i++);

    (repeat as many times as you'd like)



  • @aib said:

    Since even "unreachable code"s compile into the object file (on my compiler anyway), we need something the optimizer would throw away. How about:

    int i;

    for(i=0; i<10; i++);

    for(i=0; i<10; i++);

    (repeat as many times as you'd like)

    One of the addendums to the rules specified no repetition.



  • @PJH said:

    @aib said:

    Since even "unreachable code"s compile into the object file (on my compiler anyway), we need something the optimizer would throw away. How about:

    int i;

    for(i=0; i<10; i++);

    for(i=0; i<10; i++);

    (repeat as many times as you'd like)

    One of the addendums to the rules specified no repetition.

    Besides, i++ is an instruction. And since i is being read in i<10, no optimizer could throw away that instruction either.

    How about

    inline int foo() {
        // lots of code
    }

    int main() {
        return 1 ? 0 : foo();
    }



  • Maybe we're on the wrong track altogether though. How about this:

    #include <vector>
    using namespace std;
    typedef vector<int> vec;
    typedef vector<vec> vecvec;
    typedef vector<vecvec> vecvecvec;
    typedef vector<vecvecvec> vecvecvecvec;
    typedef vector<vecvecvecvec> vecvecvecvecvec;
    typedef vector<vecvecvecvecvec *> vecvecvecvecvecpoi;
    ... 
    int main() {
    // I'm not using vecvec... muhahahahaha!
    return 0;

    }

     



  • My submission is a gigabyte of whitespace.



  • But that will readily compile to do something , http://en.wikipedia.org/wiki/Whitespace_(programming_language)



  • @PSWorx said:

    @PJH said:

    @aib said:

    Since even "unreachable code"s compile into the object file (on my compiler anyway), we need something the optimizer would throw away. How about:

    int i;

    for(i=0; i<10; i++);

    for(i=0; i<10; i++);

    (repeat as many times as you'd like)

    One of the addendums to the rules specified no repetition.

    Besides, i++ is an instruction.

     Given no context as to what it modifies, yes. In fact I'll agree with you. i++ is an instruction.

     And since i is being read in i<10, no optimizer could throw away that instruction either.

    Is it being read? For what purpose? the loop? Only? Discard it then.



  • @asuffield said:

    My submission is a gigabyte of whitespace.

    We can only thank the stars that multiple whitespace characters collapses to one in a browser, otherwise my mouse wheel finger will be hurting now.

     



  • @PJH said:

    @aib said:

    Since even "unreachable code"s compile into the object file (on my compiler anyway), we need something the optimizer would throw away. How about:

    int i;

    for(i=0; i<10; i++);

    for(i=0; i<10; i++);

    (repeat as many times as you'd like)

    One of the addendums to the rules specified no repetition.

    I was initially going to say something around the lines of:

    for(a=0; a<X; a++); 

    Repeat using any variable name for 'a' and any integer for 'X'.

    But that would be just a subset of the possible empty loops that compile to nothing. In fact, you can have a virtually infinite number of loops using the comma operator.

     

    Then I decided against posting, then came back to post and forgot the rule.

    @PSWorx said:

    How about

    inline int foo() {
        // lots of code
    }

    int main() {
        return 1 ? 0 : foo();
    }


    How about just

    inline int foo() { /* lots of code */

    int main(void) { return 0; } 

    ?

     

    Or if un-preprocessed source counts,

    #define N 1

    #ifndef N

    (download and insert The Internet here) 

    #endif

    or even,

    #define one 1

    #define one FILE_NOT_FOUND 

    ... 

    #define two we can even use\

    multiple lines

    ...

     



  • With:

    int i; 

    for (i=0; i<10; i++);

    You can't throw out the loop - because after the loop, i should = 10.  The i++ can't be dropped.   ( try printf("%d", i); after the loop... )

    (unless of course you don't use 'i' after the loop; I dont know how far into this compiler optimizations go..)

     



  • @alapalme said:

    With:

    int i; 

    for (i=0; i<10; i++);

    You can't throw out the loop - because after the loop, i should = 10.  The i++ can't be dropped.   ( try printf("%d", i); after the loop... )

    (unless of course you don't use 'i' after the loop; I dont know how far into this compiler optimizations go..)

    Compilers of any reasonable quality will flatten the whole thing out of existence, because it's a constant. You can generally assume that any sequence of assignment and integer math will be completely flattened into the minimal form (unless you're using msvc or gcc < 4.0). There are a few corner cases with arithmetic (such as computationally intractable functions), but no amount of assignment can ever confound the standard algorithm. Nor will it be confused by mixing two unrelated sequences of computation, if there is no actual sharing of data. This includes threading it through useless loops and conditionals.

    You need actual complexity to stop a modern compiler, not the illusion of complexity. 



  • I've had visual studio flatten an over 1-million iteration loop into a single i+=1000000;

    I was trying to time the difference between normal and loop-unrolled code, and had the optimizations on a little aggressive. 



  • @Thief^ said:

    I've had visual studio flatten an over 1-million iteration loop into a single i+=1000000;

    I was trying to time the difference between normal and loop-unrolled code, and had the optimizations on a little aggressive. 

    If you already knew, the compiler would meld both versions down to the same single instruction, what was the point in unrolling the loop at all? 



  • Since this is C, just write a long string literal as a meaningless expression. 

    #include <stdio.h>
    int nix() {
            "foobarfoobar ...insert lots of text here... foobarfoobarfoobar";
    }



  • @ammoQ said:

    Since this is C, just write a long string literal as a meaningless expression. 

    #include <stdio.h>
    int nix() {
            "foobarfoobar ...insert lots of text here... foobarfoobarfoobar";
    }

    A new challenge:

    Write the longest (seemingly) functional program that gets utterly nixed by the compiler.



  • Define "utterly nixed"

    My solution:

    Download Linux source.

    Fuck around with it arbitrarily.

    Try to compile. If it does, fuck around some more. 



  • @PSWorx said:

    @Thief^ said:

    I've had visual studio flatten an over 1-million iteration loop into a single i+=1000000;

    I was trying to time the difference between normal and loop-unrolled code, and had the optimizations on a little aggressive. 

    If you already knew, the compiler would meld both versions down to the same single instruction, what was the point in unrolling the loop at all? 

    I DIDN'T know that. That's what I found out. Of course this was only benchmark code, the real code actually did something in the loop and wouldn't compress to a single instruction.

    And when I said loop-unrolled, I meant by the compiler, not by hand.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.