Iterator<vector>



  • I [used to] work for a small game company in a small country. We are constantly in desperate search for developers as C++ is not that popular anymore (who needs garbage collector anyway). As part of our interview process we give the candidate a PC equipped with Visual Studio and MSDN, two-three hours and a small game to write - the good old Snake gathering rotten fruits in order to grow.
    Here comes a promising candidate - according to the CV he is an expert in C/C++ with 7 years of experience, he has been working in our department of defense, sounds impressive. And here's most of the code he produced:

    void MyGame::Draw()
    {
         std::iterator<vector> *pzm = &zm.begin();
         while(*pzm != pzm->endl())
         {
              SetColor(pzm->getx() & 0xff, pzm->gety() & 0xff, (pzm->getx()+pzm->gety()) & 0xff);
              FillRect(pzm->getx(), pzm->gety(), 200, 100);
              pzm++;
         }
    }

    And no, it doesn't even compile.



  • I don't even remember my C++ - what is he even trying to do?



  • No, these statements will not produce a fruit-eating snake.



  • @H|B said:

    No, these statements will not produce a fruit-eating snake.
    With the right compiler it will.



  • @RayS said:

    @H|B said:

    No, these statements will not produce a fruit-eating snake.
    With the right compiler it will.

     

     I've been led to believe that if you wish hard enough, anything you put through a perl interpreter will result in what you want.



  • Well, assuming zm contains the points that the snake is currently occupying, you'll get the snake drawn with some really snazzy color gradients.  Well, if it compiled, that is.

    FillRect and SetColor.  Is that MFC?  People still use MFC?



  • @Jonathan Holland said:

    @RayS said:

    @H|B said:

    No, these statements will not produce a fruit-eating snake.
    With the right compiler it will.

     

     I've been led to believe that if you wish hard enough, anything you put through a perl interpreter will result in what you want.

     

    This is true, but only if you put all your code on one line and pepper it randomly with symbols.  And if it still doesn't work, then it will in Perl 6.



  • @vt_mruhlin said:

    FillRect and SetColor.  Is that MFC?  People still use MFC?
     

    I know people who still work directly with the Windows API.  They are sick, sad people. 



  • @bstorer said:

    I know people who still work directly with the Windows API.  They are sick, sad people. 
     

    I work directly with the Windows API.  In fact, most of the time it's the most sane way to go in order to get stuff done reliably and efficiently. 

    I'll tell you what The Real WTF is:  The Windows API itself!  Now, that's sick!!

        -dZ. 



  • I count ten(ish) WTFs in that code... geez.  That's almost two WTFs per line. 



  • @Heron said:

    I count ten(ish) WTFs in that code... geez.  That's almost two WTFs per line. 

     

     Last time I worked in C++, I found commonly accepted abbrievated variable names annoying.

     Its good to know that they are still around.

     



  •  

    Can someone iterate (*snicker*) over the WTFs in the OP for us non-C++ guys.  I get that he's creating the iterator completely wrong, but other than that it looks like he was sort of on the right track. 

    I mean, except for the fact that it the red channel is based off of the x-coordinate, green is y, and blue is both.  And that the snakes body components are going to be 200px wide and only 100px tall.

    Finally, is it common to have 2-3 hour interviews like these where you just let the prospect come in and do his own thing?  If I showed up at an interview and someone said "Yeah let's go ahead and have you write a game of Snake, you've got 2 hours" I'd get a little worried. 



  • @Outlaw Programmer said:

    If I showed up at an interview and someone said "Yeah let's go ahead and have you write a game of Snake, you've got 2 hours" I'd get a little worried. 

    "Oh you are all done? It works? Ok, that will be all, thanks for coming."

    "Hey Bill, get ready we are going to be rich!"



  • @MasterPlanSoftware said:

    @Outlaw Programmer said:

    If I showed up at an interview and someone said "Yeah let's go ahead and have you write a game of Snake, you've got 2 hours" I'd get a little worried. 

    "Oh you are all done? It works? Ok, that will be all, thanks for coming."

    "Hey Bill, get ready we are going to be rich!"

     

    Haha yeah I was thinking the same thing.  One day, have a graphics programmer come in for an interview and work on the renderer.  Bring in the AI programmer prospects the next week.  After 6 months of interviewing you end up with a finished product.  Now we'll just have to bring in some marketing interviewees and ask them how they'd market the world's worst game...



  • @Outlaw Programmer said:

    Haha yeah I was thinking the same thing.  One day, have a graphics programmer come in for an interview and work on the renderer.  Bring in the AI programmer prospects the next week.  After 6 months of interviewing you end up with a finished product.  Now we'll just have to bring in some marketing interviewees and ask them how they'd market the world's worst game...
     

    I know that is how I would run a software company!



  • The whole company was, and still is, a sad mess of good ideas, enthusiastic people, religious wars, clueless management and nice funding.



  • @Sad Bug Killer said:

    The whole company was, and still is, a sad mess of good ideas, enthusiastic people, religious wars, clueless management and nice funding.
     

    ...wait... back up.



  • @MasterPlanSoftware said:

    @Sad Bug Killer said:

    The whole company was, and still is, a sad mess of good ideas, enthusiastic people, religious wars, clueless management and nice funding.
     

    ...wait... back up.

     

     Could it be that he worked at Wisdom Tree...Makers of the worst games of all time?

     


     



  • @RayS said:

    @H|B said:

    No, these statements will not produce a fruit-eating snake.
    With the right compiler it will.

     

    snakecc?


  • Considered Harmful

    @cconroy said:

    @RayS said:

    @H|B said:

    No, these statements will not produce a fruit-eating snake.
    With the right compiler it will.

     

    snakecc?

    Ah, the compiler that ignores all input and outputs the object file for a game of Snake.



  • Worse than all 16 of these?

     



  • @Jonathan Holland said:

     Could it be that he worked at Wisdom Tree...Makers of the worst games of all time?

     


     

    Perfect segue to an obsession of mine, the Angry Video Game Nerd:

     http://www.youtube.com/watch?v=LkNvQYiM6bw

     

     



  • @emurphy said:

    Worse than all 16 of these?

     

    Sorry, but any "worst games of all time" list without either Big Rigs: Over The Road Racing or Bionic Granny is just a pretender. 



  • It's of course difficult to know for sure what this code is going to do, but whoever wrote this has more rust on his STL than me. Here is from a tutorial (declaration of a "vector" of ints, and its declaration):

     

    std::vector<int> myIntVector;

    std::vector<int>::iterator myIntVectorIterator;

     

    So the syntax is already total garbage. Then he declares the iterator to be a pointer, i.e. a sort of alias of another iterator (that doesn't exist). But the idea is clear: he wants to iterate over elements in the array zm. But then he draws just rectangles using the x and y coordinates in this vector, but we will never know if all rectangles are going to end at (200,100) or have size 200x100, because this call to FillRect doesn't exist on any platform I know. And then the color of this rectangle looks as if it's based off its x and y coordinates (red = x, green = y, blue = x + y). Try to imagine what that has to look like...

     

    However, I'm sure the compiler must have given some truly wonderful error messages. 



  • The real WTF is that he didn't write it in Windows API compliant style, like this:

    typedef struct {
    DWORD dwSize;
    LPVOID lpResult;
    } GETPOINTERSTRUCT;
    typedef GETPOINTERSTRUCT FAR *LPGETPOINTERSTRUCT;

    BOOL FAR PASCAL GetNilPointerExA(HINSTANCE hInstance, LPGETPOINTERSTRUCT lpgpsOutput) {
    if(lpgpsOutput->dwSize != sizeof(GETPOINTERSTRUCT)) {
    SetLastError(ERROR_INVALID_PARAMETER);
    return FALSE;
    }
    lpgpsOutput->lpResult = NULL;
    return TRUE;
    }


    /*
    To use it, just write the following code:

    LPVOID lpMyNull;
    GETPOINTERSTRUCT gpsMyNull;
    gpsMyNull.dwSize = sizeof(gpsMyNull);
    if(GetNilPointerExA(hInst, &gpsMyNull) == FALSE) {
    TCHAR szMsg[256];
    sprintf(szMsg, "Cannot get a NULL pointer: error code %d", (int) GetLastError());
    MessageBox(hMainWnd, szMsg, "Error", MB_ICONHAND | MB_OK);
    ExitProcess(1);
    }
    lpMyNull = gpsMyNull.lpResult;
    */


  • Damn... can some mod add a "DWORD dwReserved" field to the struct? It's missing... ;)



  •  I'm agog! The typing of the dead was challenging and innovative...maybe I'm the only person that bought it.



  • @wilko said:

     I'm agog! The typing of the dead was challenging and innovative...maybe I'm the only person that bought it.

    Yeah, I think that was a pretty horrible list. I see The Typing of the Dead on strange games lists all the time, but I've never heard a bad word about it. And the Prince of Persia entry makes me think the author might be retarded.



  • Ugh... trying, to, fix, wtf...


    void MyGame::Draw()
    {
        const int w= 200, h= 100;
         for(std::vector<ZM?>::const_iterator i = zm.begin(); i != zm->end(); ++i)
         {
              SetColor(i->x & 0xff, i->y & 0xff, (i->x + i->y) & 0xff);
              FillRect(i->xw, i->yh, w, h);
         }
    }



  • @RayS said:

    @emurphy said:

    Worse than all 16 of these?

     

    Sorry, but any "worst games of all time" list without either Big Rigs: Over The Road Racing or Bionic Granny is just a pretender. 

     

    [url]http://gtw64.retro-net.de/Pages/r/Review_Razzmatazz.php[/url]

    *The* worst game of all time.  Ever.  Bar none.



  • @OperatorBastardusInfernalis said:

    Damn... can some mod add a "DWORD dwReserved" field to the struct? It's missing... ;)

     

    That's not very Windowsy.  Surely you mean "DWORD wReserved"?  ;-)


Log in to reply