Portability

S

Stephen Mayes

From lurking on this most excellent newsgroup, I have garnered that an
expressed benefit of having a standard is portability of code.
I see a lot of open source endeavors that inspire my awe, but I can't see
how the authors get paid, so they don't much inspire my ambition for
pursuing perfection, which is inate nonetheless.
In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.
 
P

P.J. Plauger

From lurking on this most excellent newsgroup, I have garnered that an
expressed benefit of having a standard is portability of code.
I see a lot of open source endeavors that inspire my awe, but I can't see
how the authors get paid, so they don't much inspire my ambition for
pursuing perfection, which is inate nonetheless.
In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.

We do it all the time, so we can offer our products on all popular
platforms. Please note, however:

-- Portability is not a Boolean attribute, but a measure of the relative
cost of moving existing code vs. rewriting it. (If it's cheaper to move
than rewrite, we say it's "portable.")

-- It costs more time and effort up front to write code that's likely
to be portable. You may not get your investment back if you later
determine it's not worth porting.

-- The only way to make code truly portable, and keep it that way, is
to exercise it regularly on multiple platforms.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
R

REH

Stephen Mayes said:
From lurking on this most excellent newsgroup, I have garnered that an
expressed benefit of having a standard is portability of code.
I see a lot of open source endeavors that inspire my awe, but I can't see
how the authors get paid, so they don't much inspire my ambition for
pursuing perfection, which is inate nonetheless.
In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.

Hardware and compilers do go obsolete. We go through a "tech-refresh" every
3-5 years. Writing code as portability as possible really helps to cut the
time down. Even without do a refresh, we still have to support multiple
processors and compilers.

REH
 
E

Eric Sosman

Stephen said:
From lurking on this most excellent newsgroup, I have garnered that an
expressed benefit of having a standard is portability of code.
I see a lot of open source endeavors that inspire my awe, but I can't see
how the authors get paid, so they don't much inspire my ambition for
pursuing perfection, which is inate nonetheless.
In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.

Portability is just one of many desirable attributes
of a program, and it is not always the most important.
Some others are correctness, capability, maintainability,
speed, scalability, ... the list goes on. The main thing
to keep in mind is that these attributes are sometimes in
conflict, and the conflict is not (and should not be)
resolved the same way in every situation. Even correctness
is not always paramount -- in some real-time situations it
may be more important to get an approximate answer *right
now* than to get a fully accurate answer two seconds late.
The engineer is always performing a balancing act.

That said, portability is more desirable today than it
used to be, and is becoming still more desirable with the
passage of time. The reason is economic: Once upon a time
computer power was expensive and programmers were cheap,
but today skilled labor is expensive while computers have
become cheap. Once upon a time it made sense to use a lot
of labor to move a program from Machine A to Machine B, so
that the program could take advantage of A- or B-specific
features to run more efficiently or compute more accurately.
Today, it makes far less sense to resort to the machines'
idiosyncracies; it's cheaper to waste a few cheap CPU cycles
than to try to recoup the extra cost of expensive labor.

Again, though, I emphasize that none of these desirable
attributes trumps all the others in all situations. If you
find yourself writing for somebody's Web-enabled toaster you
may sacrifice some portability to squeeze the code into just
one ROM chip instead of two. Reducing the per-unit cost by
a buck-fifty on a manufacturing run of a million toasters
saves a million and a half dollars, which (just between the
two of us) is more than enough to buy a week of *my* labor.

Finally, "portability" is not a Boolean attribute; I do
not even believe it is one-dimensional. "Portability" may
be best characterized in terms of a likely set of target
platforms (which amounts to a guess about the future of the
program) and the labor required to get the program working
on those platforms (another kind of guess, whose difficulty
is described in "The Mythical Man-Month"). When we say that
this or that construct "is portable" or "isn't portable,"
we're using a kind of short-hand for considerations that are
much fuzzier, much harder to characterize than "is/isn't"
makes them sound.

Do I, personally, write "portable" code? Yes, always!
My code is "portable to all the systems of interest," just
like everyone else's. The question becomes whether I've
got a good idea of the universe of systems that are or will
eventually become "interesting" ...
 
M

Martijn

In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even
more than one?

I tend to split my code into three categories:

* generic code *
This is code which I think serves a more general purpose and is just as
useful on different platforms than the one I am developing at the time.
When I code these fragments, portability takes precedence over performance.

* specific code *
This is code that works on things like the GUI, the OS or uses platform
specific libraries. Unless I use a cross-platform GTK I basically don't
worry about writting code that will work accross many platforms. Of course
I do keep in mind that slight alterations in the platform (such as Win9x and
WinNT) will not break the code. Emphasis is mainly on readability and - I
hope - maintainability.

* "tight" code *
I break the above rules only when I feel that performance is an issue. What
I usually end up doing is writing a more readable version and "translating"
that into a more efficient version, keeping a copy of the old code.
 
J

john_bode

Stephen said:
In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.

The bulk of the products I have worked on have had to run concurrently
on Windows and one or more Unix platforms, usually AIX, Solaris, HP-UX,
and recently Linux. One project had to run under Windows 3.1, MacOS,
and Solaris. I can't think of any product I've worked on that hasn't
had to either support multiple platforms concurrently or be ported to a
different platform at some point, regardless of the language used.

Note that most of this was non-graphical, server-side code, so I
usually didn't have to deal with GUI weirdness (the one time I did, we
were using a GUI framework designed for cross-platform development).
 
A

Anonymous 7843

In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.

The product I was working on in 2002 was required to be portable
to AIX 4.2 and 5L, OSF/1, HP/UX 10.20 through 11i, Solaris 2.6
through 2.8, Redhat Linux 7.2 through 9.0, Windows NT, 2000, and XP,
and basically a standing offer to port to whatever the customer
wanted so long as they were willing to pay. MacOS X wouldn't
have been out of the question, though CICS probably would have
met with some pushback.

And it wasn't just ANSI standard C that we had to port--there was
tons of threading, sockets, and POSIX-ish stuff in there, plus it
interfaced with a large 3rd-party app with it's own porting issues.
(GUI was handled by another group, so that was one headache I didn't
have to deal with.)

But it really wasn't that bad. After a while, you just get used to
the various machine-specific foibles and/or wrap stuff up into
portability libraries. The rest of the time, you write to
the standards (ANSI and/or POSIX) as best you can, live with
some #ifdef WIN32's in a couple dozen places and just keep an
open mind.

The product (line) I'm working on now is a little less ambitious,
but we're definitely covering linux, solaris, and windows. A salesman
stopped by the cubicle farm just last week asking about an HP/UX
port. We told him to get us a machine and we'd do it.
 
F

Flash Gordon

Stephen said:
From lurking on this most excellent newsgroup, I have garnered that an
expressed benefit of having a standard is portability of code.
I see a lot of open source endeavors that inspire my awe, but I can't see
how the authors get paid, so they don't much inspire my ambition for
pursuing perfection, which is inate nonetheless.
In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.

I'm currently working on SW that is used on 3 platforms split across 2
processors. We are dropping support for one of the platforms, but will
probably be taking on more platforms including running native 64 bit
when we have the time.
 
C

CBFalconer

P.J. Plauger said:
.... snip ...

-- It costs more time and effort up front to write code that's
likely to be portable. You may not get your investment back if
you later determine it's not worth porting.

I would say "may cost more". It often adds no cost, and may even
be cheaper because there is no need to examine or know of system
specific quirks. The major problem is knowing what is and is not
portable in the first place. Once you do, you can make conscious
decisions and isolate the non-portable stuff to appropriate
modules.

IMO the best aid in attaining this nirvana is to keep the warning
level high on your compilers. At a minimum, for gcc, I would use
"-W -Wall -ansi -pedantic". I also like -Wwrite-strings, but
tastes may vary. When you _really_ need something relaxed, banish
it to a separate module and comment the bejasus out of it.

It's like any other sport. If you have good form, watch your
footwork, and keep in practice things will be much easier. Here we
have the advantage of a tireless coach who can point out the
slippages in form before they become bad habits.

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 
E

Emmanuel Delahaye

CBFalconer wrote on 21/06/05 :
IMO the best aid in attaining this nirvana is to keep the warning
level high on your compilers. At a minimum, for gcc, I would use
"-W -Wall -ansi -pedantic". I also like -Wwrite-strings, but
tastes may vary.

And -O or -O1-9 in order to trig the data flow control. It's the only
way to get the 'use of uninitialized variable', and other gems, warning
messages.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

I once asked an expert COBOL programmer, how to
declare local variables in COBOL, the reply was:
"what is a local variable?"
 
M

Malcolm

Stephen Mayes said:
In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.
The code I'm writing at present soaks up lots of processing power. Currently
it runs on a UNIX box, but should it be used for "real life" rather than as
an experimental method, people would probably want to be able to run it on
any fast machine. So it is all 100% portable ANSI C.
 
W

Walter Roberson

:In real life, how many of you knowledgable people are ever actually
:consigned to write code that will port to very many systems, if even more
:than one? Historical anecdotes aside. Let's say within the last five
:years.

All my scientific programming in the last decade was written to
ANSI C + POSIX.1 (possibly with an interface to IDL or other ported
languages). I deliberately do NOT write using gcc, because I don't
want to accidently get into bad habits by using a gcc extension.


Ah, I just remembered that the above is a bit of a lie: a little
less than a decade ago, some of my active development was still
in Fortran 77 (avoiding extensions).


My Systems Administration programming is usually nowhere near as
portable, but Systems Administration work is often a big collection
of long-lived ad hoc tasks. If you are analyzing logs or probing the
network or rejigging process priorities or telling the tape robot to
switch tapes, then you are probably doing is probably non-portable ;-)
 
A

Anonymous 7843

I deliberately do NOT write using gcc, because I don't
want to accidently get into bad habits by using a gcc extension.

Were you unaware of gcc -ansi -pedantic?
That cured many of my bad habits.
 
W

Walter Roberson

Were you unaware of gcc -ansi -pedantic?
That cured many of my bad habits.

I stopped trusting gcc's conformance early on, when I read the
documented argument that gcc was at liberty to define any
token it wanted (e.g., the token for ANSI C) because gcc wasn't
an ANSI C compiler and ANSI only had authority over compilers that
claimed to be ANSI.
 
R

robert.thorpe

Stephen said:
From lurking on this most excellent newsgroup, I have garnered that an
expressed benefit of having a standard is portability of code.
I see a lot of open source endeavors that inspire my awe, but I can't see
how the authors get paid, so they don't much inspire my ambition for
pursuing perfection, which is inate nonetheless.
In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.

I agree with what people have said so far.
I would add two things:

* I'm currently working on a GUI program with only a simple processing
part.
In this program the platform-dependent user interface part is ~1000
lines for one particular platform and will be 2000-2500 before I'm
finished. I expect the platform-dependent parts altogether to be ~5000
lines and the portable processing part to be ~1000 lines. So, for some
programming the complexity introduced by supporting several platforms
can be high.

* When supporting many platform as others have said: separate the
platform dependant code and use conditional compilation. It's very
useful if the platform dependant code doesn't test the platform
directly (e.g. like #ifdef WIN32) very often.
It's often better to derive properties of the various platforms then to
act on those properties, for instance #ifdef HAS_ALLOCA where
HAS_ALLOCA is defined earlier.
 
M

Michael Wojcik

In real life, how many of you knowledgable people are ever actually
consigned to write code that will port to very many systems, if even more
than one? Historical anecdotes aside. Let's say within the last five
years.

Everything I've worked on professionally for the past five years has
been required to be portable among at least 32-bit MS Windows and
40-some flavors and versions of 32-bit and 64-bit Unix and Unix-like
platforms (and yes, there are frequently portation issues among the
Unix flavors, efforts like SUS notwithstanding). Some of it has had
to be portable to other architectures as well, such as the AS/400.
And we're moving toward more implementations, not fewer.

For some products, we are *still* supporting a few C implementations
which are not C90-compliant. That means maintenance updates to those
products have to conditionally-compile function prototypes and ISO-
style function definitions.
 
M

Malcolm

P.J. Plauger said:
-- It costs more time and effort up front to write code that's likely
to be portable. You may not get your investment back if you later
determine it's not worth porting.
This a common misunderstanding. The primary reason for making code portable
is not to move it to another system, as the layman would naturally suppose,
but to improve the sturcture of the code by separating algorithms from input
and output.
-- The only way to make code truly portable, and keep it that way, is
to exercise it regularly on multiple platforms.
No. Simply use a language that enforces portability, like Java, or use C
carefully. Admittedly C has the problem of "good enough" portability - eg
all bits zero representing a null pointer, or the execution character set
being ASCII. This can be overcome with only a small amount of training.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top