Books I Read: Write Portable Code

I recently read Write Portable Code by Brian Hook. I have to say that it was a nice introduction to what you need to worry about when writing code.

I didn’t pay attention to the fact that it was supposed to be an introduction, and at one point I was concerned that it was too high level. Of course, if it tried to cover each topic in depth the book would be way thicker. Still, it was very informative and gave me some things to think about when I write my code. It covered some issues that almost invariably come up when trying to port code.

If I learned nothing else from this book, it was the idea that writing portable code should never be done for the sake of it. If you want to write a program that is perfectly portable, you may end up sacrificing a lot of time and effort that doesn’t make it worth it. For me, I want to make games that run on at least three platforms: Windows, Mac OS, and Gnu/Linux. Ideally I would like to write code that compiles on anything I throw at it, but Hook points out that you should never just write portable code. It has to be portable for a reason, and the more you clarify why you want it to be portable and HOW portable you want it, the easier the job will be. For me, my three targets are very specific, and while BSD shouldn’t be too much of an issue to port to, I should decide up front if I want to support or it or not. I shouldn’t write my code and have an idea of a BSD port nagging at me from the back of my mind. Similarly, if I want to support something like the Pocket PC or Palm OS, I should not make that decision once a project is almost finished. As Hook says, when you write portable code, you write code to be portable. Even if I don’t know the exact platforms I want to support, I should have an idea if I will require multiple threads, megabytes of memory, or any number of things that can’t be assumed on different architectures and platforms.

I should always have clarity of purpose, and it was just eye-opening to think about it in terms of writing portable code. Write Portable Code is definitely a book I will be rereading and studying in the future.

Comments are closed.