Difference between revisions of "Writing portable code"

From GNUstepWiki
Jump to navigation Jump to search
 
Line 3: Line 3:
 
Some portability gotchas are listed below (please update when you run into a new one!):
 
Some portability gotchas are listed below (please update when you run into a new one!):
  
'''MacOS X developers'''
+
== MacOS X to GNUstep ==
  
...should try and avoid CoreFoundation as this will complicate your dependency situation on non-Mac hosts, even if that part of CoreFoundation has actually been ported.
+
OS-X developers should try and avoid CoreFoundation as this will complicate your dependency situation on non-Mac hosts, even if that part of CoreFoundation has actually been ported.
  
 
GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner.
 
GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner.
  
'''All the world is not Linux'''
+
Use following to distinguish between Cocoa and GNUstep
  
...or FreeBSD or Windows. System constants may be different on different platforms. Paths to command-line tools, the parameters they accept and locations of temporary directories may be different to what you are used to on your platform.
+
#ifdef GNUSTEP
 +
    ''/* GNUstep code goes here ... */''
 +
#else
 +
    ''/* OS-X Cocoa native code goes here ... */''
 +
#endif
  
* GNUstep Base and the FoundationKit offer some of this functionality "for free".
+
''' ''FIXME: add following:'' '''
* Try not to hard code paths and so on into your code, use macros, or even better an abstraction mechanism.
+
* how to port interface (.nib) files
 +
* how to convert xCode project to GNUstep project (makefile or [[ProjectCenter]])
 +
 
 +
== Notes ==
 +
 
 +
=== Do not rely on tools available in development environment ===
 +
 
 +
All the world is not Linux or FreeBSD or Windows. System constants may be different on different platforms. Paths to command-line tools, the parameters they accept and locations of temporary directories may be different to what you are used to on your platform.
 +
 
 +
* GNUstep Base and the [[FoundationKit]] offer some of this functionality "for free".
 +
* Try not to hard code paths and so on into your code, use macros (not recommended), or even better an abstraction mechanism.
 
* Avoid hard-coding system constants, or platform-specific ones where Posix or commonly-accepted ones exist (and we're not talking about glibc here :-)
 
* Avoid hard-coding system constants, or platform-specific ones where Posix or commonly-accepted ones exist (and we're not talking about glibc here :-)
 +
 +
[[Category:Project procedures]]

Revision as of 15:21, 28 February 2005

GNUstep opens up some fairly interesting opportunities to target a number of platforms with the same source code, for example porting MacOS X Cocoa applications to Linux, the BSDs, other Unices and (ultimately) Windows without significant re-engineering effort or degraded end-user functionality.

Some portability gotchas are listed below (please update when you run into a new one!):

MacOS X to GNUstep

OS-X developers should try and avoid CoreFoundation as this will complicate your dependency situation on non-Mac hosts, even if that part of CoreFoundation has actually been ported.

GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner.

Use following to distinguish between Cocoa and GNUstep

#ifdef GNUSTEP
    /* GNUstep code goes here ... */
#else
    /* OS-X Cocoa native code goes here ... */
#endif

FIXME: add following:

  • how to port interface (.nib) files
  • how to convert xCode project to GNUstep project (makefile or ProjectCenter)

Notes

Do not rely on tools available in development environment

All the world is not Linux or FreeBSD or Windows. System constants may be different on different platforms. Paths to command-line tools, the parameters they accept and locations of temporary directories may be different to what you are used to on your platform.

  • GNUstep Base and the FoundationKit offer some of this functionality "for free".
  • Try not to hard code paths and so on into your code, use macros (not recommended), or even better an abstraction mechanism.
  • Avoid hard-coding system constants, or platform-specific ones where Posix or commonly-accepted ones exist (and we're not talking about glibc here :-)