A few weeks ago I applied for the “software apprenticeship” position at Groupon. As part of the application I was tasked with building a Tic Tac Toe program using the language of my choice. Sounds simple enough right? Well, turns out building a “children’s” game in Ruby is a little bit harder than I anticipated! However, thanks to my trusty Ruby “Pickaxe” book, the awesome videos on Treehouse, and hours of testing in IRB, I had myself a program that actually played a game of tic tac toe against a human.
Was it perfect? No. Was the code elegant and clean? Absolutely not. Did it work? Yes. Did I learn a ton? Yes. Was I proud of my work? You bet your ass! If I were to break my experience down in to a 3 part story it would go a little like this:
Build a tic tac toe game? No problem, I can do that!
Oh S#!@…I hate tic tac toe, I’m never going to be able to figure this out!!!!!!
Oh S#@!…it works, this is awesome!!!!!
Learning to program is a long and difficult journey, but it’s incredibly fun and rewarding if you can work your way through the bumps in the road. Below are some tips, tricks, and lessons I learned from my tic tac toe experience:
Back to basics: Implementing a successful solution requires a detailed understanding of the problem you’re trying to solve. I probably thought about how I was going to build the program for 5 hours before I actually wrote a single line of code. I actually hand wrote tic tac toe boards and played games against myself and other people to make sure I fully understood all of the possible moves and strategies available.
Make it work, then make it right: My code is far from perfect and I have a lot of refactoring to do, but that’s ok. As a beginner, I think it’s more important to make it work first, then try to refactor and make it right. If you don’t know how to work with hashes and/or arrays, you better learn! Ruby is awesome! The more you understand, the more you realize how powerful you can become.
If you don’t use IRB, start using it now! While exercises like this may be very challenging, they are excellent practice. Since I played basketball I’ll use a sports metaphor…building a rails app is similar to playing the game. It feels more real and is a lot more fun. Building a tic tac toe game in ruby is more comparable to practice. It’s like running sprints or shooting thousands of free throws. It may not always be as fun and it may feel more difficult, but it’s what makes you play the game better. At least that’s how it felt in my head.
In conclusion, building a tic tac toe game was a really fun and challenging exercise. The amount of ruby knowledge I obtained in one week was stagering and completing the problem was extremely rewarding. Having a challenge, with a deadline, is a great way to not only stretch your ability but also to learn at an accelerated pace. I encourage anyone trying to learn programming to try and complete this exercise…at the very least you’ll enhance your problem solving skills!
If you want to check out my code, here’s a link to my github profile.