PDA

View Full Version : what does portability mean?



elad
09-30-2002, 08:52 AM
Here's a simple question that I haven't seen bandied about, but can't say I review this board much, so I apologize if I am in error on that.

What does the phrase, cross platform portability, mean? Does it mean if I compile a program using only standard C++ it will run on Windows and Apple and Unix platforms or it will compile on all three platforms? I mean if I write a program with non-standard code and the exe (or whatever) file runs on all three platforms, does it really matter if it compiles on all three platforms or not?

Maybe the answer is---depends. If you are a hobbyist (like me) and don't care about code maintenance issues, or if you don't care about compatability with other platforms, then it's probably not a big deal. But if you are a professional programmer and code maintenance is an issue or if you are looking for the broadest possible market for your product, then portability is a potentially big issue.

ober
09-30-2002, 08:56 AM
Basically portability means that you can run your programs on many systems. There's a standard (usually ANSI) that all (or most) OSes adhere to as far as understanding code. As long as you stay within those standards, you programs should work fine... however C++ is a lot more tricky to do this with than maybe just C.

Prelude
09-30-2002, 09:31 AM
Portable programs can be moved to another platform and compiled without changes or with minimal changes.


Maybe the answer is---depends. If you are a hobbyist (like me) and don't care about code maintenance issues, or if you don't care about compatability with other platforms, then it's probably not a big deal. But if you are a professional programmer and code maintenance is an issue or if you are looking for the broadest possible market for your product, then portability is a potentially big issue.

This is a naive view, but still correct to some extent. I see portability as a measure of quality. If you don't need to use non-portable features of a platform then a portable program should be written for the sake of good style. If you do need to use non-portable features, you should modularize them sufficiently so that porting the program to another platform is relatively painless. For example, the following program is not portable and if it were huge would be a pain to modify:


#include <stdio.h>
#include <stdlib.h>

int main ( void )
{
/* Do stuff */

system ( "cls" );

/* Do more stuff */

return 0;
}

The problem is that using "cls" as the argument to system will break on platforms that do not use cls as a clear screen command. If system ( "cls" ) were called hundreds of times then porting this program would be...well, put bluntly it would be a real *****. It could be better written like this:


#include <stdio.h>
#include <stdlib.h>

void clear ( void )
{
system ( "cls" );
}

int main ( void )
{
/* Do stuff */

clear();

/* Do more stuff */

return 0;
}

The non-portable feature is still there, but the effort it takes to change that feature to suit a new platform is as simple as changing "cls" to "clear" or some other command.

So basically, the measure of portability for a program, or modularization to ease portability, is a good measure of program quality. Program quality is something every programmer should strive for, the end result should be portable simply because you as the programmer care about quality, even if portability isn't a concern for you.

-Prelude

Shadow
09-30-2002, 10:11 AM
> even if portability isn't a concern for you
..it might be for someone else.
(Open-source)

elad
10-02-2002, 02:39 PM
Thanks.

The answers confirm my suspicion that the concept is murky. At least when two respectable programmers disagree, (one says runs, the other says compiles), then in my mind the concept isn't cut an dried.

Or maybe it means that run and compiles are one and the same????

Betazep
10-02-2002, 02:41 PM
No... it is 'compiles' and not 'runs'.

A program that is compiled on a windows machine will not run on linux (usually) and vice versa. But a portable program should be able to be compiled on either with little to no changes and then run.

"Program quality is something every programmer should strive for, the end result should be portable simply because you as the programmer care about quality, even if portability isn't a concern for you."

And that has to be really close to the coolest programming statement I have ever heard.

adrianxw
10-03-2002, 02:46 AM
>>> the concept is murky

Not murky. Truly portable code should compile on other systems. The object produced by a compiler cannot be expected to run on different hardware - the processor opcodes for example, would not be the same.