How to make sure it worked



  • I just stumbled upon the following C++ code snippet here at my work:

    result = getReturnID(msgID);
    result = 7;
    switch(result) {
        case 4+3:
            cout << "valid return ID result!" << endl;
            break;
    }

     

    Now to find the original programmer and find out what his thought process here was.... 



  • It looks to me like somebody was trying to learn a thing or two, mostly about how switches work, and never removed the test code.



  • Aggreed, I'd also guess someone was wondering if the switch() statement allows for constant expressions (instead of literals), and tried it out.



  • I've seen worse.  An outsourcing company sent us the following in sample code, when we were considering outsourcing some work to them:

     


    switch($_POST['somevar'] == 0) {

      case 'somestring':
         dostuff();
         break;

      case 'somethingelse':

         domorestuff();

         break;

      default:

          dosomethingelse();

          break;
     

     

     

    ...Obviously, this *always* defaults, no matter the value of $_POST['somevar'].  To make matters worse, this "pattern" was used in multiple files.

     

    The real WTF?  The boss hired these guys anyway.  'cause hey, they write bad code that doesn't work, but they'll do it for $5/hr! 



  • @merreborn said:

     

    The real WTF?  The boss hired these guys anyway.  'cause hey, they write bad code that doesn't work, but they'll do it for $5/hr! 

    Woes I'm very familiar with.

    We get intern-level code, but hey, it's cheap.

    Yes.

    Yes it is.



  • @dhromed said:

    @merreborn said:
     

    The real WTF?  The boss hired these guys anyway.  'cause hey, they write bad code that doesn't work, but they'll do it for $5/hr! 

    Woes I'm very familiar with.

    We get intern-level code, but hey, it's cheap.

    Yes.

    Yes it is.

    Wouldn't by that logic "no code at all" for $0/hr be even cheaper than "practically no code" for $5/hr ?



  • @dhromed said:

    @merreborn said:
     

    The real WTF?  The boss hired these guys anyway.  'cause hey, they write bad code that doesn't work, but they'll do it for $5/hr! 

    Woes I'm very familiar with.

    We get intern-level code, but hey, it's cheap.

    Yes.

    Yes it is.

    I would hope interns could do better than that. 



  • @Balthazaar said:

     

    Now to find the original programmer and find out what his thought process here was.... 

    I'm betting they were something along the lines of "Damn, I've run out of beer!"



  • Hey, now. Interns aren't all bad. Some of them are actually smart. This is rare, but just look at Asok.


Log in to reply