Oxygene (programming language)
Adapted from Wikipedia · Adventurer experience
Oxygene is a special kind of programming language made by RemObjects Software. It works on different systems like Microsoft's Common Language Infrastructure, the Java Platform, and Cocoa. Oxygene is based on a language called Object Pascal, but it also uses ideas from C#, Eiffel, Java, F#, and others.
Unlike an older version called Delphi.NET, Oxygene was built to use the best features of modern systems like .NET and Java. You can use Oxygene with Microsoft's Visual Studio on Windows or with a special tool called Fire on macOS.
Oxygene is a product you need to buy, and it works with several different development tools. It is one of six languages supported by the Elements Compiler, along with C#, Swift, Java, Go, and Mercury. Over the years, Oxygene has changed and grown, and now you can use it to make programs for many different devices and operating systems.
The language
The Oxygene language started from Object Pascal and Delphi. It was changed to follow .NET programming rules and create fully CLR-compliant assemblies. Some small features from Object Pascal and Delphi were removed or changed. New and modern features, like Generics or Sequences and Queries, were added to the language.
Oxygene is an Object-oriented programming language. This means it uses classes to build programs. Classes can hold data and run code. Classes are like blueprints for objects. For example, the idea of an apple is a blueprint for any actual apple. We know that an apple has a color, and that it can be peeled. These are the data and actions for the apple class.
Oxygene supports features for running tasks at the same time to make programs faster. It can use all the cores or processors of a computer. The .NET Framework has a ThreadPool class to help manage several threads. The Task Parallel Library (TPL) was added in .NET 4.0 to give more tools for running tasks together.
Operators can be given new meanings in Oxygene using the class operator syntax:
class operator implicit(i : Integer) : MyClass;
Note, that for operator overloading each operator has a name, which must be used in the operator overloading syntax. For example, "+" would not be a valid method name in Oxygene.
Code examples
Hello World
Here is a simple program that prints “Hello World!”:
namespace HelloWorld;
interface
type
HelloClass = class
public
class method Main;
end;
implementation
class method HelloClass.Main;
begin
writeLn('Hello World!');
end;
end.
Generic container
This example shows how to create a list that can hold different kinds of data:
namespace GenericContainer;
interface
type
TestApp = class
public
class method Main;
end;
Person = class
public
property FirstName: String;
property LastName: String;
end;
implementation
uses
System.Collections.Generic;
class method TestApp.Main;
begin
var myList := new List;
myList.Add(new Person(FirstName := 'John', LastName := 'Doe'));
myList.Add(new Person(FirstName := 'Jane', LastName := 'Doe'));
myList.Add(new Person(FirstName := 'James', LastName := 'Doe'));
Console.WriteLine(myList.FirstName);
Console.ReadLine;
end;
end.
Generic method
This example shows how to write a method that can work with any kind of data:
namespace GenericMethodTest;
interface
type
GenericMethodTest = static class
public
class method Main;
private
class method Swap(var left, right : T);
class method DoSwap(left, right : T);
end;
implementation
class method GenericMethodTest.DoSwap(left, right : T);
begin
var a := left;
var b := right;
Console.WriteLine('Type: {0}', typeof(T));
Console.WriteLine('-> a = {0}, b = {1}', a , b);
Swap(var a, var b);
Console.WriteLine('-> a = {0}, b = {1}', a , b);
end;
class method GenericMethodTest.Main;
begin
var a := 23;
var b := 15;
DoSwap(a, b);
var aa := 'abc';
var bb := 'def';
DoSwap(aa, bb);
DoSwap(1.1, 1.2);
Console.ReadLine();
end;
class method GenericMethodTest.Swap(var left, right : T);
begin
var temp := left;
left:= right;
right := temp;
end;
end.
Program output:
Type: System.Int32
-> a = 23, b = 15
-> a = 15, b = 23
Type: System.String
-> a = abc, b = def
-> a = def, b = abc
Type: System.Double
-> a = 1,1, b = 1,2
-> a = 1,2, b = 1,1
Differences between Delphi and Oxygene
Oxygene changed some parts of Delphi to work better. For example, it uses the word [namespace](/wiki/Namespace) instead of unit, because Oxygene compiles whole projects at once, not just single files.
It also prefers the word method over procedure and function, though both still work. In Oxygene, all methods can handle multiple versions automatically, so you don’t need a special word for that. The way to start creating an object also changed from .Create() to the new word, though you can still use the old way if you want by changing your project settings. Strings in Oxygene act a little differently: their characters start counting from zero, they can’t be changed, and they can have "nil" values, meaning sometimes checking if a string is empty isn’t enough.
Criticism
Some people wanted to move their old programs made with Delphi to Oxygene without changing much. But this is hard because Oxygene looks similar to Delphi but has enough differences that you can't just switch them easily.
Also, Oxygene does not include the Visual Component Library, which many Delphi programs use. This makes moving programs from Delphi to Oxygene even harder.
Related articles
This article is a child-friendly adaptation of the Wikipedia article on Oxygene (programming language), available under CC BY-SA 4.0.
Safekipedia