When it comes to creating code in a program, it is inevitable that there will be bugs – errors in the code that prevent it from executing properly. While computer language might seem complicated, it operates on a rather simple basis.
Writing code is essentially writing a list of instructions for the computer to do, starting at the very beginning and then proceeding down in sequence. In a sense, it works like a recipe: if I mess up on any of the steps, I’ll create something that either is different from what I desired or just doesn’t work out. But if I follow all the steps to the letter, I’ll produce something that is exactly what the recipe called for. There is a slight problem, however, when I translate this analogy to a “computer recipe”.
The ingredients are all variations of data that are typed out in a computer language. If my program isn’t working, then I have to figure out the location of my error. Programs that compile code often aid in this process and provide the lines that contain the error. The real problem is fixing the error. The computer is called a computer for a reason, and if I give it something it cannot compute, then it will simply freeze up. The error can be large and convoluted, or it can also be something as simple as stating “1 + 1 = 3” – a common typing mistake.
Programming code involves as much writing as debugging. It’s incredibly frustrating at times when I can’t figure out what went wrong. On the other side of the coin, it’s gratifying to finally find a error, fix it, and see my program run correctly!
I decided to talk about debugging in this article because I ran into an error that I was unable to fix and was ready to give up on my project. Eclipse, the program I used to write and compile Java code, kept indicating that there were errors in my code, and highlighted several lines. Because these lines of code were dependent on other lines of my code, much like a step of a recipe is dependent on the prior steps’ completion, I couldn’t pinpoint exactly which line of code I had written incorrectly. What I ended up doing was rewriting and copying the code several times – but the error still remained.
Currently I’m following a tutorial for game programming, and one part of the tutorial requires me to create an image that would serve as a pattern for grass. It turns out I had saved “grass.png” not as a PNG (graphic) file but a PSD (Photoshop) file and stuck a “.png” at the end. The code I had written was looking for a graphic file, not a Photoshop file, even if they had the same name. My debugging process ended up as a “saving a file correctly” issue.
Even though I spent a frustratingly unnecessarily large amount of time fixing this tiny error, I still got a kick out of seeing grass on my screen. Part of the pleasure I take out of programming is seeing my little monstrous creations come to life.
When it comes to popular titles released into the market, debugging is a process crucial for their success. Companies have “alpha” and “beta” testers, who basically test a game for errors at various stages before its release. These testers do everything they possibly can to find an error and basically do everything that the game doesn’t want them to do. This trial-and-error process of finding and destroying bugs results in a truly polished product.
The best testers, however, are actually the players themselves. The trial-and-error process of finding bugs becomes much more effective when there are hundreds of thousands, or even millions of players running around in the game. Games in the App Store frequently receive updates that include bugfixes, improving the quality of the game even while people are actively playing the game.
I might not like the high-blood-pressure-inducing process of debugging, but it’s a necessary component of the game creation process!
Words by Kelvin Pan
Images made in Adobe Photoshop and Flash