Unity 3D and iOS Development
Old School Code Review – Pen & Paper
Every once in a while when I get to a certain point in a project, I like to back up and make sure I’m not missing the forest for the trees. That’s when I print out a lot of code and head for the coffee shop.
Forest for the trees
Getting down and dirty in the code and living in the code editor is what programmers really enjoy doing, but it’s good sometimes to take a few steps back. I start by identifying all of the major pieces of code (if a class has only has a few lines and one function, I can probably skip it for this review) and make sure I’ve got a stack of paper in the printer. Next, I make sure that whatever IDE or editor I’m using supports syntax highlighting when printing because not all of them do. When I’m programming with Unity, this typically means UniSCITE which has syntax highlighting in both code and print and supports highlighting the various keywords and comments and things like that. Of critical importance is that comments and comment blocks are colored, preferably in a color like green that is still readable but doesn’t just jump off the page. You want your code to jump off the page at you, not your comments. If your editor prints out page numbers and filenames on each page at the top or bottom — all the better.
Code Review, Old School
Next, I print it all out and head to the coffee shop. After I settle in with a large cup of black coffee, I start by going through every page of every file looking over the code. Sometimes I’ll find things that are redundant, or things that will speed up a section by moving variables or initializations outside of a loop or things that can be combined. I use my pen and write notes on the page as I go, whether it’s a comment to myself about something that could be optimized or moved to another class, something I want to look into for optimization, or something I want to check out because I think it might be the source of trouble I’m having. It’s all too easy to dig around in the code and be lazy (and sloppy) when you’re trying to optimize or troubleshoot, but if you can get an overview, you’ll often see a LOT of things that you missed before.
The bigger picture
As I’m going through the code, I usually end up using an extra piece of paper or two to write out more notes on about different ways to approach a particular piece of code, or a new module/class that I want to write to combine some existing functionality. After I’ve gone through all of the code looking for the line-by-line, function-by-function type stuff, I’m also going to be a lot more familiar with all parts of the code. The last time I did this in my game, there were parts of the code that I wrote months earlier and hadn’t touched since because they were working fine. However, having gone through and re-familiarized myself with everything, I realized that there was a lot of room for improvement and consolidation. I ended up finding and fixing a few bugs, getting a better idea of how (and where) to redo a few things and consolidating some code by combining functions and making them a little more flexible.
Your Milage May Vary
If your code would take up a ream of paper (or even half a ream), then this technique probably isn’t for you. Most of the projects that I’m doing, even with a couple thousand lines of code, don’t end up being a huge stack of paper. Even if it did end up being quite a bit, you could still do this same thing with just one or two of the larger classes/files. I’ve also had success using this technique if I’m trying to get familiar with someone else’s code, whether it’s an existing project I’m picking up to work on or an open source project that I’m trying to get more familiar with. I’ve used this technique many, many times over the years and it’s always proved useful to some degree every single time I’ve used it. Typically, it yields very good results and I come away with better code, cleaner code and faster code. When you’re trying to distinguish yourself from all the other pieces of software out there, these things can make a huge difference. Lastly, if you give this a shot or have similar practices, I’d love to hear about the results.
This blog post is part of the #iDevBlogADay initiative for indie iOS developers. Click here to read more posts from the iDevBlogADay website.
| Print article | This entry was posted by Greg on March 31, 2011 at 10:38 pm, and is filed under Game development. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |







about 2 years ago
What about using something like iPad instead of printing out the stuff? I believe there are apps that support writting notes onto text or pdf files.
about 2 years ago
Interesting idea to do a code review in Pen and Paper. While I haven’t tried that technique, I never work without my note book by my side and I never start building a new class without at least some rudimentary planning – much like CRC cards.
In response to the comment above about doing it on an iPad – No way! I know for me personally that there is something, for lack of a better word, intimate about pencil and paper. There’s something about the feel that can really get me engaged and it’s completely separated from other distractions. Pencil and paper are probably the closest my objects will ever get to being actual tangible objects.
about 2 years ago
My heart aches when I think of all those Amazonian trees that were destroyed only to be used for printing CODE. I mean.. CODE? What’s wrong with code review using.. I don’t know.. a laptop and a code EDITOR?
All you’d need to do is go through the same process, only use comments to add your suggested tweaks, and don’t try to change things right away, but instead just plan the future changes and redesigns.
about 2 years ago
Evgeni: I’ve tried using the iPad for stuff like this, it’s just not the same. Being able to spread out all the pages of a program across a table and really get the big picture makes a huge difference.
Kyle: Give it a shot! Let me know if you try it and how it works out for you.
Alex: I do that constantly. But sometimes you need a different perspective. I think the app needs to be planned and occasionally reviewed while you’re not sitting at the computer in the code editor. It’s far too easy to jump in and do the “fun stuff” of programming without the due diligence of planning if you’re just sitting there.
about 2 years ago
I completely agree with you on this one. I often use this approach myself when I’m nearly done with some documentation. I have however not used it much for coding – yet.
Nothing beats the pen and paper when it comes to the more abstract and non-linear approaches to getting the big picture. Looking at a computer screen is way too restricted in terms of where you can move next.