Oxygene Language Platform Differences Overview

To do: MOVE TO SHARE BETWEEN LANGUAGES!?

This page provides an overview of the few subtle differences for the Elements compiler and the Oxygene language on the three different platforms – .NET, Cocoa and Java.

We strive for 99% language compatibility, but due to the nature of the platforms and underlying runtimes, a small handful of language features will not be available on all platforms, and a few platform-specific features are provided that don't make sense on the other platforms.

Also read in more detail about edition-specific language features:

Garbage Collection vs. ARC

Memory management on .NET, Java anf Island uses Garbage Collection while Cocoa uses Automatic Reference Counting, also referred to as ARC.

In most code scenarios, GC and ARC will behave pretty comparably, and code written that deals with object references generally will look the same — i.e. will not worry about explicitly freeing object memory. There are, however, some subtle differences, in particular when it comes to dealing with retain cycles, which GC has no problem resolving, but which can cause leaks in ARC. Special Storage Modifier keywords (strong (implied by default), weak and unretained) are provided to help with this on the Cocoa platform.

Also unique to the Cocoa platform, the autoreleasepool keyword is provided to manually instantiate additional auto-release pools, where needed. This is seldom the case, but might be necessary in some specific cases. The topic on ARC will go into this in more detail.

See also Automatic Reference Counting vs. Garbage Collection

Blocks (a.k.a. .NET Delegates)

Blocks, i.e. method references, are supported on on all platforms, but there are some limitations.

The block keyword is provided on all platforms, and synonymous with the now deprecated delegate keyword (refer to the Blocks topic for reasons for this change).

Oxygene has support for inline block types in method or property declarations. This syntax is supported on all platforms, but limited to block signatures that match an existing .NET Framework Action or Func delegate signature on .NET.

Note that on Cocoa, the function, procedure and method keywords will declare C-level Function Pointers when used for block type declarations, rather than true Objective-C blocks (i.e. C's * syntax opposed to ^ block syntax). Only the block and delegate keywords declare true Objective-C blocks. (On .NET and Java, all 5 keywords behave the same way.)

Since on .NET and Java it has never been recommended to use function, procedureprocedure and method for block declarations, it is recommended to consistently stick to [[block (keyword)|block]] for cross-platform code.

Note: For RemObjects C#, this equally applies to delegate types. Inline delegate type declarations are permitted. Because C# does not use different keywords like Oxygene does, the [FunctionPointer] [Attribute](Special Attributes (Cocoa)) can be applied to mark a delegate as a function (and not a block) pointer in C#.

C Runtime Heritage and Influences on Elements for Cocoa

Due to it being built on the Objective-C runtime, which itself is a true superset of standard C, Oxygene for Cocoa gains support for a wide variety of concepts from the C language, not the least of which being access to the vast C runtime library, with printf() and thousands of other well known functions, records and types. Due to C being inherently non-object-oriented, this means Oxygene for Cocoa provides access to non-OOP libraries and functionalities in a manner that would have been deemed "unacceptable" on the strictly-OOP .NET and Java platforms.

Examples of these are more liberal use of pointers and reference parameters, global constants and functions, and the more traditional method-less Record types.

For the purpose of cross-platform code, this is mainly irrelevant, as such code can (and should) stick to using the higher-level OOP based features and functionality.

Attributes

Custom Attributes are supported in the .NET and Java editions, but not on Cocoa. However, the standard attribute syntax with square brackets ([]) is supported on Cocoa to specify a limited range of special attributes defined by the compiler (as on the other platforms). These special attributes are not backed by classes.

Cirrus

The compiler supports applying aspects on all platforms, including Cocoa and Java, using the same syntax as attributes (with the optional [aspects:...] scope prefix).

Since aspects essentially run as part of the compiler, aspects continue to be written using in .NET, no matter the target platform. Aspects can be created so that they are platform-independent and can be applied to any of the four platforms. In fact, that is the default behavior.

Properly named aspects (with the *Aspect class name suffix) can be applied like regular attributes on all platforms.

Miscellaneous and Minor Differences

  • Boxing semantics differ between .NET, Java and Cocoa.
  • Nullable Types, like boxing, have some limitations on Cocoa (namely that they support only numerical values, and no Records).
  • Arrays support differs on Cocoa, with the availability of non-object Open and Static Arrays.
  • As part of ARC, Storage Modifiers are supported on Cocoa only.
  • Interfaces support optional members on Cocoa.
  • The dynamic type is only supported on .NET and Cocoa, and on the latter maps to id type and provides sightly different usage semantics.
  • unsafe code is not supported on Java, and all code is assumed to be unsafe on Cocoa and Island, making the keyword ignored/unnecessary on that platform.
  • Generic co/contra-variance is supported on .NET only.
  • Differences in [Pointer References in Oxygene for Cocoa](Pointer References in Oxygene for Cocoa).
  • The external keyword is supported on .NET (P/Invoke) and Java (JNI), but not applicable on Cocoa.
  • Parallel "for" loops, parallel sequences and queryable sequences are currently only supported for .NET.

Temporary differences

The list below represents minor differences that exist now but are planned to be rectified/unified in future language updates:

  • Special Java-style exception handling extensions will be a new platform difference, once implemented.
  • BigInteger support is currently only supported for .NET. Support for Java & Cocoa is under review for a future update.
  • await is currently only supported for .NET. Support for Java & Cocoa is under review for a future update.