[nSLUG] Non-portable code is poorly written code

Ben Armstrong synrg at sanctuary.nslug.ns.ca
Sun Dec 18 09:29:05 AST 2005


On Sat, 2005-12-17 at 20:56 -0400, Jack Warkentin wrote:
> It is a little bit more than simply "poorly written source" or "buggy 
> code".

No, it is simply that.  Code that is non-portable is not written for
general consumption.  Code that is accepted into a multi-architecture
distribution like Debian that won't work on all architectures is buggy.
There are, of course, a few packages that are deliberately non-portable,
targetted at specific architectures because they are finely tuned for
the special capabilities of those architectures, but those are the
exception, not the rule.

If you're writing a library and need to do things at a lower level, you
may need to resort to #ifdef to deal with different architectures, but
most people don't write that sort of library.

If you're writing application code, you should use portable libraries to
get the job done.  Any #ifdef that exposes the details of the underlying
architecture can and should be concealed behind an API in a portable
library.  If a portable library isn't available for what you want to do,
you should at least abstract out any architecture-specific
implementation details into a separate module.

Of course, writing portable code isn't always the easist thing to do.
Many programmers are lazy, and so write code from the assumption that
everyone uses the architecture of their development machine.  But it
isn't impossible, and once you're practiced in it and it becomes habit,
you'll have far fewer surprises when a user tries to run your code on a
Macintosh or AMD64.  A disciplined modern programmer should be concerned
with portability from the very outset.  It is far easier to build
portable code from scratch than it is to later clean up the mess you'll
make if you take a shortcut by writing non-portable code.  Save yourself
the time up front and strive to be portable for every piece of code you
write.

Ben


!DSPAM:43a56425297691255870621!




More information about the nSLUG mailing list