Pages

Sunday, August 28, 2011

Book Review: Write Portable Code

There are not a lot of books on portable code, but Write Portable Code: An Introduction to Developing Software for Multiple Platforms by Brian Hook does a good job handling many of the topics.

There are a number of rules for portability:

- Never assume anything (memory, size of built in types (int, float etc.)).
- The code will likely have to have non-portable elements to run efficiently.
- Establish a reasonable baseline of platforms, (not both PS3 and Commodore 64).
- Never read or write structures from memory or cast raw bytes to a structure.
- Always convert to or from a canonical format when moving data in or out of memory.
- Develop good habits and use tools and platforms that cooperate to strong practices.
- Avoid new langages or library features.
- Integrate testing.
- Use compile time assertions and strict compilations (avoid excessive conditional compilations).
- Write straightforward code.
- Understand anything can change between compilers (floating point can work different).
- Leverage portable third party libraries, but be careful.
- Performance and resource usage must be as portable as your features.
- Portability also means supportin other cultures, regions and languages.
- Consider using a language more suited to the task (python, C#, etc. are easier than C++).
- Systems are becoming more secure (folders, ports etc.).

Brian Hook also has a POSH (Portable Open Source Harness) at http://hookatooka.com/poshlib/ that demonstrates some examples of portability and a good stepping stone for those looking at porting C++.

I think the book was useful it demonstrates a number of source code examples for his Simple Audio Library (SAL). Brian Hook also goes through a number of examples of the different standards including the IEEE 754, C8 and C99 standards, which are interesting to look at from a portability focus, and it would great if more books looked at the standards in their work.

Bye for now,
Michael Hubbard
http://michaelhubbard.ca

No comments:

Post a Comment