Thursday, April 06, 2006

Book Review: Writing Portable Code


Brian Hook’s Write Portable Code: An Introduction to Developing Software for Multiple Platforms is an in-depth discussion of issues involved in getting C/C++ code from one platform to another. Hook dives deep into arcane topics such as processor memory access alignment, floating point operation platform differences, and exception handling. The book’s not for the faint-of-heart, and it’s rather specific to C/C++; however, readers brave enough to push through the book should get interesting insights regardless of what platform and development environment they’re working with.

Disclaimer: I got this book free from No Starch Press as a review copy.

I should note that while I’ve had experience on a fairly wide range of platforms in several different languages, I’ve not dealt specifically with portability issues. I also would not by any means consider myself a C/C++ guru.

Who It's For

Hook’s preface gives a great list of folks who might find the book useful. Paraphrasing, his list includes developers who experiment with different platforms at home, developers moving a product to a different platform in hopes of capturing more market share, game developers who have client and server portions on different platforms, folks dealing with mobile/desktop environments, and vertical integration vendors who’ve lost a platform.

To this list I’d add anyone interested in general sound software engineering practices, particularly knowing when to try and abstract or wrap something out, and when to just press on with implementation. A theme constant throughout the book is Hook’s mantra “define reasonable baselines.”

Who It's Not For

Don’t look to this book for specifics on portability for anything other than C/C++. While there’s some very thought-provoking text on general topics like filesystems, user interaction, and general scalability, all the code’s in C/C++.

What It Covers

Hook uses C/C++ for his examples because “they are ubiquitous and tend to contribute to portability problems.” I found his assertion that “ANSI C and C++ are probably the most unportable languages that were still intended to be portable” pretty funny and of course spot on.

As I mentioned in the overview, the book’s got tremendous detail on a great number of topics. Hook covers a great deal of specifics like differing compiler flags, safely serializing and deserializing data, byte ordering for storage, memory management idiosyncrasies, and even function calling convention differences.

Hook carries two software products through the entire book, using them as examples for various issues. POSH, the Portable Open Source Harness, is a set of C99-like type definitions Hook developed for assisting in cross-platform compilation. He also uses his Simple Audio Library (SAL) to clearly and excellently demonstrate specific issues such as thread handling or exporting/importing DLLs when working on a Windows platform.

There’s also great detail on higher-level, but still important topics like data formats, user interaction, and scalability. Hook’s example of time differences for a simple database querry vs. a binary tree implementation is very pertinent because he shows the small gains made on a fast system vice the enormous gains made on a Palm Zire PDA.

He briefly covers internationalization and localization, one of the several topics applicable to all developers. His points about dealing with Unicode, currency, and even keyboard differences are good items for all developers to consider, regardless of their environment.

What It Doesn't Cover

As already mentioned, there’s no real discussion of languages other than C/C++, aside from Chapter 17’s very short blurbs on scripting languages where Python, Lua, and Ruby are quickly covered.

It’s also surprising that he doesn’t cover Visual Source Safe in his discussion of source control systems in Chapter 4. I know that VSS is wildly unpopular in many arenas, but it’s also widely used – even in some non-Windows development shops. Still, he gives only brief detail to the other covered systems (rcs, cvs, Perforce, BitKeeper, Subversion, and GNU arch), so it’s not like readers will miss a great deal.


This appears to be a great resource for folks who are actively porting software. It’s a very good guidebook of issues to address if you’re even thinking about porting. I’d also say it’s a good skimming read for most developers if only to get an understanding of some engineering principles to consider when building your systems. You never know when your platform might fold or get deprecated.

No comments:

Subscribe (RSS)

The Leadership Journey