doom3This week a friend of mine linked Kotaku’s article “The Exceptional Beauty of Doom 3’s Source Code”. After a quick glance, I decided to save it (as well as the link to Fabien Sanglard’s posts about it) for further and in-depth reading. I’m not a videogame programmer, and I don’t want to become one. Ok, I wanted to become one when I began my bachelor’s degree, but that’s another story. So why reading about how to properly code a videogame? Because in the end videogames are just another type of programming projects. Once you go below the surface and enter the code, it doesn’t matter if it is from a blockbuster game or from the most advanced virtual stock exchange trader. It’s just code. And videogames are HUGE projects. There are many lessons to learn there about structure, readability, reusability and maintainance of the code.

And that is exactly what I wanted to talk about here today. Something that is not very encouraged by universities (at least not by mine) but should be is reading code. Reading hundreds and thousands of lines of good code is crucial for a computer science engineer to become a good programmer. Because apart from knowing the theory for basic algorithms, data structures and design patterns it is really important to see how they are used in real life. So that is my today’s advice: read code written by people who has been programming for 20 or 30 years. Read open source projects, the Linux kernel, and the Doom 3 source code.

Emilio Duro, in his talks about business, optimism and welfare (in Spanish), states that, in order to improve your way of doing something what you must do is look for the gurus, see how they do it, and copy them. Do exactly what they do. And by doing it, you become them. So you become one of the best. To which I add: Do it, but always with critical thinking. Even gurus make mistakes, or do things that can be improved.

So learn from them, copy their code (but understand exactly what it does and why), but don’t be afraid of proposing your own solutions if you think that you can solve a problem more efficiently. And if you think that downloading the latest Linux kernel and starting to read it is a task too huge, why don’t you start by reading, at least, some Style Guides (for example the ones for Google C++ and Linux kernel). They detail the reasons, pros and cons for the programming style decisions taken, and they will help you to improve your code.

Read code, learn code, copy code
Send to Kindle

One thought on “Read code, learn code, copy code

Leave a Reply

Your email address will not be published. Required fields are marked *