Portability

Started by
6 comments, last by Nytegard 17 years, 8 months ago
I recently started caring about writing portable code. If some asks me, "Hey v0dKA, can you code X for me?", I want to respond immediately with "Sure! Just give me a couple years" instead of "Well, what operating system are you using? Unix? Mac? Oh, that sucks, probably not..." In an effort to realize this wish, I decided to abandon the Windows API entirely and start using wxWidgets, a library designed for just this purpose. I haven't learned about all its caveats yet, but it looks very promising. Looking at all the interfaces it provides shows that it not only does the windowing (GUI) stuff, but also such things as networking (including support for HTTP and FTP), dynamic arrays as well as other containers, HTML parsing, document/view management, file operations, command line parsing, data/time, RTTI, logging features, streams, multithreading, XML, help systems, database support, DLL loading, etc (starting to sound like a commercial). But... if I compile an executable that I built using wxWidgets, does that really mean that I can hand this executable to a Windows user, hand out another copy to a *nix user, and another copy to a Mac user? Is the same executable going to run on all the operating systems? Or must the code be actually compiled on the individual machines in order to run on them? In other words, is it the output file or only the code that is portable across all the platforms?
.:<<-v0d[KA]->>:.
Advertisement
You must recompile it on every machine/OS you wish it to run on.

i.e. you cannot build a windows .exe and expect it to run on linux
Quote:Original post by CoyCash
You must recompile it on every machine/OS you wish it to run on.

i.e. you cannot build a windows .exe and expect it to run on linux


I see, thanks.

So how is it usually done if a client asks a coder to make them a program, but their operating systems don't match? In such a case, does the coder have to own the operating system of the client in order to be able to compile the application for the client? Does the coder request that the client download a compiler and ask him to compile it himself (eek)? Or, perhaps, are there special tools for this?

Thanks again for the help.
.:<<-v0d[KA]->>:.
Quote:Original post by v0dKA
So how is it usually done if a client asks a coder to make them a program, but their operating systems don't match?

It's usually done in a portable language like Java, Python or Perl. Code written in these languages can potentially run on any operating system given that there is an interpreter (or virtual machine) installed.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
You'd still be crazy to try to release something for a system it hasn't been tested on, so that doesn't gain you much. Either way you still need access to the target system.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
Quote:Original post by RAZORUNREAL
You'd still be crazy to try to release something for a system it hasn't been tested on, so that doesn't gain you much. Either way you still need access to the target system.


Exactly. The main problem with cross platform code, is there really isn't such a thing in reality imho. Even Java has certain areas where certain libraries are specifically for one operating system or another. Just one of my pet peeves when I download a piece of code that claims to be cross platform, only to see #include <unistd.h> or #include <conio.h>, etc. People get use to their own development system, that they tend to overlook small things which make code platform specific.

The only true way to make sure your executable is cross platform is to make sure first hand that it compiles and works on the operating system.
I see, thanks for the comments.

So if I want a portable executable, I would have to use something like C#? Or Visual Basic.NET? Or for that matter, any .NET language?

Or is there still the compiling-on-the-platform requirement? Will using .NET do anything?
.:<<-v0d[KA]->>:.
Java would typically work also. Don't read my previous comment as it definately won't work. I'm just stating that there are times where even the most portable language in the world won't necessarily work the same, if at all, on every system.

IE: On one of the previous programs I developed for work, I ran into an issue on something which was common in the Win32 SDK, but such availability didn't exist in C#. So I called PInvoke to get it working. I'm willing to bet that such code would not compile should you try building it on a Mac.

As for compiling, you don't have to compile on the platform, there are plenty of compilers for other systems you can us. I do this so I can use Visual Studio, compile it in Windows, then run it on another piece of hardware. At the same time though, debugging can be hard without the system.

This topic is closed to new replies.

Advertisement