Can't get enough of you




  • This is some obfuscated code (to protect the innocent) demonstrating the use of memory allocation combined with exception handling.

    {
      VarType *var = 0;

      try
      {
        while(itr())
        {
          try
          {
            delete var;
            var = new VarType();

            if (!someCondition)
            {
              delete var;
              var = new VarType();
            }

            delete var;
            var = 0;
          }
          catch(...)
          {
          }

          delete var;
          var = 0;
        }
        delete var;
        var = 0;
      }
      catch(...)
      {
      }

      delete var;
      var = 0;
      return ok;
    }



  • @GuntherVB said:

    (to protect the innocent)

    Doesn't look like the guy's innocent.  He does need to be protected though.   



  • So beautiful it brings a tear to my eye...



  • Damn. Enough repetition to look like a code stutter.



  • var = 0;
    delete var;

     It's been a while since I've done C++. Isn't this a segfault? Does delete actually perform a read on that address, or does it just try to drop it from the internal allocation table? 

    God, this editor is horrible!

     



  • @Nether said:

    var = 0;
    delete var;

     It's been a while since I've done C++. Isn't this a segfault? Does delete actually perform a read on that address, or does it just try to drop it from the internal allocation table? 

    God, this editor is horrible!

     

     

    None of those. The standard says delete should do nothing for NULL pointers. Deleting some random pointer not returned by new is undefined behavior 



  • This is truly beautiful in so many ways...

    1) Superb try-catch abuse. Bonus points for the empty catch(...) block.

    2) Completely oblivious to the stack, auto_ptr, RAII or basically anything for sensibly managing memory

    3) Repeatedly allocating and deleting inside a loop. (Perhaps not a WTF but certainly stupid). Reallocating for no good reason inside the if-block.

    4) The insistence that var be must set to 0 after being deleted, particularly the one immediately before the return.

    4) My personal favourite, returning "ok" (presumably a bool or int). The author has succeeded in using exceptions when there was no need and not using them when there was. Superb.

    The Real WTF is how someone so clearly damaged managed to even write syntactically correct C++ in the first place. 

     



  •  Just read this over on xkcd

     

     



  • @JukeboxJim said:

    4) The insistence that var be must set to 0 after being deleted, particularly the one immediately before the return.

    That's actually a good habit to get into: since it's much easier to catch a null pointer dereference than a dereference of a formerly-valid pointer, you should always zero pointers after deleting them. An unneeded assignment can be optimized away by the compiler, but a missing assignment where it's needed will lead to hard-to-spot bugs.



  •  This is the best WTF I've ever seen.  I'm in a really low resolution right now, so I had to keep scrolling to read the code. Every time another "delete var;" came up my joy was magnified by 10x. Then, after exiting the try-catch blocks -- a final "delete var;" to really seal the deal and make my day!

     



  • @superjer said:

     This is the best WTF I've ever seen.  I'm in a really low resolution right now, so I had to keep scrolling to read the code. Every time another "delete var;" came up my joy was magnified by 10x. Then, after exiting the try-catch blocks -- a final "delete var;" to really seal the deal and make my day!

     

    I submit that TRWTF is the idea of resolutions lower than 1024x768 still existing in the wild ;) 



  • @misguided said:

    I submit that TRWTF is the idea of resolutions lower than 1024x768 still existing in the wild ;) 

    I know that you're joking, but the proportion of users browsing with a VGA or below resolution is probably increasing, thanks to the ever-increasing smartphone market. Then again, there are those of us browing on 46" screens. :)



  • @RayS said:

    Then again, there are those of us browing on 46" screens. :)

    I like browsing on my TV, too.



  • @misguided said:

    I submit that TRWTF is the idea of resolutions lower than 1024x768 still existing in the wild ;) 
    In class we have a person with 20/400 (or is it 400/20? He's not here so I can't ask) who needs to have his resolution at 800x600, 640x480 is preferred though, but XP doesn't do that normally. Not everyone has normal eyesight.



  • @Lingerance said:

    20/400 (or is it 400/20? He's not here so I can't ask)

    I believe it's 20/400.  Means that he can see at 20 feet what a normal person can see at 400 feet.  20/200 (with corrective lenses) is legally blind, so I hope your classmate is not driving a car.

    [quote user="wikipedia"]In North America and most of Europe, legal blindness is defined as visual acuity
    (vision) of 20/200 (6/60) or less in the better eye with best
    correction possible. This means that a legally blind individual would
    have to stand 20 feet (6.1 m)) from an object to see it with the same
    degree of clarity as a normally sighted person could from 200 feet
    (61 m)).[/quote]

    Babe Ruth was about 20/15 or 20/10.  They say he could read the numbers on a license plate from a distance where most people couldn't even tell the color.



  • @RayS said:

    @misguided said:

    I submit that TRWTF is the idea of resolutions lower than 1024x768 still existing in the wild ;) 

    I know that you're joking, but the proportion of users browsing with a VGA or below resolution is probably increasing, thanks to the ever-increasing smartphone market. Then again, there are those of us browing on 46" screens. :)

     

    I submit that TRWTF is the idea of legions of people browsing the Daily WTF Sidebar on their smart phone.  THE FUTURE IS NOW APPARENTLY, AND IT'S FULL OF GEEKS ;) 



  • @misguided said:

    I submit that TRWTF is the
    idea of legions of people browsing
    the Daily WTF Sidebar on their
    smart phone.

    Hey, the sidebar is all that fits on this

    tiny screen.



  • @Lingerance said:

    @misguided said:
    I submit that TRWTF is the idea of resolutions lower than 1024x768 still existing in the wild ;) 
    In class we have a person with 20/400 (or is it 400/20? He's not here so I can't ask) who needs to have his resolution at 800x600, 640x480 is preferred though, but XP doesn't do that normally. Not everyone has normal eyesight.
     

    I'm assuming that's not normal near-sightedness. Otherwise he doesn't need a low res, but some nice strong glasses.

    I have -9 in both eyes. Without my glasses I see sharply at about 2-3 inch. Amazing how thin they can still make the lenses.



  • @belgariontheking said:

    egal blindness is defined as visual acuity
    (vision) of 20/200 (6/60) or less in the better eye with best
    correction possible

    Hm.

    Or maybe, say, 1/10? I'm not sure why they chose "20/200" -- and then explicitly simplified it with "6/60", which seems sort of random.



  • @dhromed said:

    I'm not sure why they chose "20/200" -- and then explicitly simplified it with "6/60", which seems sort of random.

    Well;

    This means that a legally blind individual would have to stand 20 feet (6.1 m)) from an object to see it with the same degree of clarity as a normally sighted person could from 200 feet (61 m)
    It's not simplified, it's metric. I wonder if that form is actually used anywhere, though.


  • @dhromed said:

    Or maybe, say, 1/10? I'm not sure why they chose "20/200" -- and then explicitly simplified it with "6/60", which seems sort of random.
    That would only make sense if the quality of eye-sight degrades on a straight graph, since it is heavily altered by the individual's perception one would presume that it is not a straight graph.



  • @Lingerance said:

    @dhromed said:
    Or maybe, say, 1/10? I'm not sure why they chose "20/200" -- and then explicitly simplified it with "6/60", which seems sort of random.
    That would only make sense if the quality of eye-sight degrades on a straight graph, since it is heavily altered by the individual's perception one would presume that it is not a straight graph.
     

    Except that 20/200 and 6/60 is the same 1/10 ratio.

    So far with what I got, saying "20/200 (6/60) visual acuity" is equal to "1/10 semantic noise".



  • @dhromed said:

    @Lingerance said:

    @dhromed said:
    Or maybe, say, 1/10? I'm not sure why they chose "20/200" -- and then explicitly simplified it with "6/60", which seems sort of random.
    That would only make sense if the quality of eye-sight degrades on a straight graph, since it is heavily altered by the individual's perception one would presume that it is not a straight graph.
     

    Except that 20/200 and 6/60 is the same 1/10 ratio.

    So far with what I got, saying "20/200 (6/60) visual acuity" is equal to "1/10 semantic noise".

    The mechanics of focusing don't scale like that. I'm nearsighted, but that just means that my eyes can't bring distant objects into sharp focus, not that I've got an overall reduced visual acuity. For a standard 20-foot eyechart, my uncorrected vision is around 20/200 -- but scale the chart down and bring it within six inches of my nose, and I'd be able to read the whole thing just fine.



  • @dhromed said:

    @Lingerance said:

    @dhromed said:
    Or maybe, say, 1/10? I'm not sure why they chose "20/200" -- and then explicitly simplified it with "6/60", which seems sort of random.
    That would only make sense if the quality of eye-sight degrades on a straight graph, since it is heavily altered by the individual's perception one would presume that it is not a straight graph.
     

    Except that 20/200 and 6/60 is the same 1/10 ratio.

    So far with what I got, saying "20/200 (6/60) visual acuity" is equal to "1/10 semantic noise".

    20 feet (approx 6.1 meters) is the distance you are supposed to stand from the visual test charts, therefore they are used as a baseline =)

     http://en.wikipedia.org/wiki/Visual_acuity



  • @Carnildo said:

    The mechanics of focusing don't scale like that. I'm nearsighted, but that just means that my eyes can't bring distant objects into sharp focus, not that I've got an overall reduced visual acuity. For a standard 20-foot eyechart, my uncorrected vision is around 20/200 -- but scale the chart down and bring it within six inches of my nose, and I'd be able to read the whole thing just fine.

    I have 20/150 vision in my left eye, and 20/15 in my right.  Makes the world very flat...  :)

    My last physical, they started with my left eye for the eye exam.  I think the nurse was a bit concerned when I said "I think the second line is 'J', 'M', 'C'."  She certainly looked much happier when I switched eyes and read the copyright notice at the bottom of the chart...



  • @GalacticCowboy said:

    She certainly looked much happier when I switched eyes and read the copyright notice at the bottom of the chart...

    I have 20/200 in both of my eyes. I love getting new glasses because sometimes I end up with 20/15 for a while. It's awesome being able to read small print so clearly. It levels out to 20/20 after a week or two, though.

    I'm just glad modern lens manufacturing makes it possible for me to have thin lenses. When I was a kid, it was so blatantly obvious that I have really bad eyesight because the lenses were around 3/8" thick. I'd wear contacts now, but all of the ones I tried ended up making my eyes really irritated.



  • @AbbydonKrafts said:

    I'd wear contacts now, but all of the ones I tried ended up making my eyes really irritated.
     

    Yeah but to be fair, having one of these in each eye is bound to hurt.

     



  • @GalacticCowboy said:

    I have 20/150 vision in my left eye, and 20/15 in my right.  Makes the world very flat...  :)
     

    Have you considered a monocle? 



  • @bstorer said:

    @GalacticCowboy said:

    I have 20/150 vision in my left eye, and 20/15 in my right.  Makes the world very flat...  :)
     

    Have you considered a monocle? 

     

    Or a pirate's eyepatch. Either would be pretty badass.



  • @MasterPlanSoftware said:

    @bstorer said:

    Have you considered a monocle? 

     

    Or a pirate's eyepatch. Either would be pretty badass.

    +1. You'd be a trendsetter with that monocle. Did you hear men's hats are coming back in style? Throw us all back to the 1800's, will ya? I'm tired of the Britney Spears era.



  • @AbbydonKrafts said:

    @MasterPlanSoftware said:

    @bstorer said:

    Have you considered a monocle? 

     

    Or a pirate's eyepatch. Either would be pretty badass.

    +1. You'd be a trendsetter with that monocle. Did you hear men's hats are coming back in style? Throw us all back to the 1800's, will ya? I'm tired of the Britney Spears era.

     

    An eyepatch AND a monocle. You would be like a cross between Hook and Mr. Peanut. Throw in a cane for the helluvit.

    Who's got photoshop warmed up?



  • @MasterPlanSoftware said:

    An eyepatch AND a monocle. You would be like a cross between Hook and Mr. Peanut. Throw in a cane for the helluvit.

    The cane is mandatory when wearing a monocle. Just wouldn't be right without it.

    I wonder what a typical employer would think if someone came in dressed like that.



  • @AbbydonKrafts said:


     

    I wonder what a typical employer would think if someone came in dressed like that.

     

    That should be the next 'code challenge'. Just walk in like nothing is wrong, and appear to not notive their reactions at all. I think you should have a tux as well.

    But we need some photographic or video proof. Maybe you could hire SS for the day?

    I hear you can pay him in rocks... Or pot.



  • @GuntherVB said:


    This is some obfuscated code (to protect the innocent) demonstrating the use of memory allocation combined with exception handling.

    {
      VarType *var = 0;

      try
      {
        while(itr())
        {
          try
          {
            delete var;
            var = new VarType();

            if (!someCondition)
            {
              delete var;
              var = new VarType();
            }

            delete var;
            var = 0;
          }
          catch(...)
          {
          }

          delete var;
          var = 0;
        }
        delete var;
        var = 0;
      }
      catch(...)
      {
      }

      delete var;
      var = 0;
      return ok;
    }

     

    WHUT IS THIS HERE GOBBLEDY GOOK MESSING UP THE PRETTY COMPUTER TECHNICION CHAT ROOM?  MY SISTER TED CAN PROLLY READ THIS CUZ SHE READS ALL THOSE CITY BOOKS WITH THE GERLS. I LIKE TO KEEP THE PICTURES IN MY BATHROOM WHEN I DO #2 IN CASE I NEED TO BE IN THERE LONG. THE MISSUS ALWAYS SCREEMS AT ME AND SHE SAYS TED COME OUT AND FIX THIS HERE COMPUTER BEFORE I CLEAN YOUR CLOCK. 

    MY BROTHER TED SAYS THAT COMPUTERS ARE LIKE WOMEN HARD TO UNDERSTAND AND EVEN HARDER TO PROGRAM. YOU COMPUTER TECHNICIONS KEEP WRITTEN ALL THAT THAR GOBBLEDY GOOK AND YOU'LL GO BLIND I RECKON.



  • @magetoo said:

    @dhromed said:
    I'm not sure why they chose "20/200" -- and then explicitly simplified it with "6/60", which seems sort of random.
    Well;
    This means that a legally blind individual would have to stand 20 feet (6.1 m)) from an object to see it with the same degree of clarity as a normally sighted person could from 200 feet (61 m)
    It's not simplified, it's metric. I wonder if that form is actually used anywhere, though.

     

    I'm not an optometrist (IANAO?) but my better half is and from what I remember...

    The 20/20 notation is based on imperial, 6/6 (as we use in the UK) is metric.  I think the first 6 (or 20) is the distance from the chart (6m or 20ft), and the second number is the arc subtended (measured in minutes) by the letter you can read (although not sure how this works in the imperial system).  So if you're 6/6 you can read something that subtends an arc of 6 minutes at 6 meters, if you're 6/12 you can only read something that subtends 12 minutes at 6m, ie twice the size.

    Any real optoms reading please feel free to flame/correct!



  • @upsidedowncreature said:

    I'm not an optometrist (IANAO?) but my better half is and from what I remember...

    The 20/20 notation is based on imperial, 6/6 (as we use in the UK) is metric.  I think the first 6 (or 20) is the distance from the chart (6m or 20ft), and the second number is the arc subtended (measured in minutes) by the letter you can read (although not sure how this works in the imperial system).  So if you're 6/6 you can read something that subtends an arc of 6 minutes at 6 meters, if you're 6/12 you can only read something that subtends 12 minutes at 6m, ie twice the size.

    Any real optoms reading please feel free to flame/correct!

     

    The second number is the distance from which an "average" person should be able to see it.  But don't ask me how they define "average."



  • @bstorer said:

    The second number is the distance from which an "average" person should be able to see it.  But don't ask me how they define "average."

    I'm sure angles come into it somewhere, I'll check with her tomorrow...

    Average != WTF reader, surely?



  • @upsidedowncreature said:

    @bstorer said:

    The second number is the distance from which an "average" person should be able to see it.  But don't ask me how they define "average."

    I'm sure angles come into it somewhere, I'll check with her tomorrow...

    Average != WTF reader, surely?

     

    From the 'pedia: "In the term '20/20 vision' the nominator refers to the distance in feet from which a person can reliably distinguish objects separated by an angle of 1 arc minute. The denominator is the distance related to a person with standard VA [visual acuity]."



  • @bstorer said:

    @upsidedowncreature said:

    @bstorer said:

    The second number is the distance from which an "average" person should be able to see it.  But don't ask me how they define "average."

    I'm sure angles come into it somewhere, I'll check with her tomorrow...

    Average != WTF reader, surely?

     

    From the 'pedia: "In the term '20/20 vision' the nominator refers to the distance in feet from which a person can reliably distinguish objects separated by an angle of 1 arc minute. The denominator is the distance related to a person with standard VA [visual acuity]."

     

    Nominator ??

    Didn't they used to call the thing on the top the numerator?

     



  • @Quinnum said:

    Nominator ??

    Didn't they used to call the thing on the top the numerator?

     

    How dare you question something found in Wikipedia!  Clearly it nominates things in its spare time. 


Log in to reply
 

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