Minesweeper and interviewing
Today I've read this article on interviewing and I decided to take the challenge:
You have one hour to implement as much of Minesweeper as possible. I've provided a JSBin for you though you're free to use whatever development tools/libraries/frameworks you're most comfortable with. You're allowed to use whatever internet resources you need, excluding plagiarism. I'll be available to answer any questions you may have. You're not expected to finish! In fact, no one ever has. Do your best and we'll chat about how things went afterward.
I've fired my editor (not really, it was already open), took note of the time and started coding. After 35 minutes I got interrupted, so I ran git init and saved the first commit. When I got back on it I worked for another 20 minutes, and then thought “time's up”, so I saved the second commit. I then took a break from it, but as the problem would not want to go away from my head, I realized that fixing the algorithm to elnarge empty areas is trivial. While doing that I found another bug in counting the number of neighboring mines. 3 commits later, and the game is actually playable (note, that includes a couple more commits polishing things up, but feel free to checkout the repo locally and see it at commit 5). Total time spent on the first 5 commits, discounting breaks, about 1:10 (and I didn't use any framework nor the JSBin template).
Some things combined to help me get this time:
Google, MDN and Stack Overflow.
the code isn't pretty and I didn't care about that; for example only one instance can be shown in a page, due to the global listener for mousedown; also, the board is fully redisplayed on each move in the ugliest way possible (generating HTML in a string). Could be cleaned up without much effort, but not within the same hour.
the game is definitely incomplete; it has no timer, the mines are not placed in such a way that you can always win without luck, and you don't even know how many of them are (it's random; again, this is easy to fix).
I'm a touch typist and I use Emacs. I know, I know, you're not interested, but without typing fast you can't get that done in an hour. And Emacs is a black magic genre that I've been practicing for 18 years and got pretty good at. Do not underestimate the power of the Force! ツ1
But then, I thought, would I be able to do the same in actual interview conditions? Most probably not. I screwed up even simpler tasks in interviews. I've worked on this little game as if all my life was about implementing Minesweeper clones, but under interview pressure, instead of being on the problem my brain is like “This guy is watching me. Yeah.. And I'm sitting here like an idiot and my hands aren't typing the marvelous code that he expects to see. Err, what was I supposed to do?”
So, even if I proved myself I could do it, I don't think I'd like to get a similar task in an actual interview. Now, back to playing Minesweeper.