| Oberon Programming Language |
Article Index for Oberon |
Information AboutOberon Programming Language |
| CATEGORIES ABOUT OBERON-2 | |
| programming languages | |
| oberon programming language family | |
Oberon-2 is an extension of the original Oberon Programming Language that adds limited reflection and Object-oriented programming facilities, open arrays as pointer base types, read-only field export and reintroduces the FOR loop from Modula-2. It was developed in 1991 at ETH Zurich by Niklaus Wirth and Hanspeter Mössenböck , who is now at Institut für Systemsoftware (SSW) of the University of Linz, Austria. Oberon-2 is a superset of Oberon , and is fully compatible with it. Oberon-2 was a redesign of Object Oberon . Oberon-2 inherited limited reflection and single inheritance ("type extension") without interfaces or mixins from Oberon, but added efficient virtual methods ("type bound procedures"). Method calls were resolved at run-time using C++ -style virtual method tables. Compared to fully object-oriented programming languages like Smalltalk , in Oberon-2 basic types are not objects, classes are not objects, many operations are not methods, there is no Message Passing (to a certain extent it can be emulated by reflection and through message extension, as demonstrated in Oberon System 3), and polymorphism is limited to subclasses of a common class (no Duck Typing like in Smalltalk / Ruby , and it's not possible to define interfaces like in Java ). Oberon-2 does not support Encapsulation at object/class level, but modules can be used for this purpose. Reflection in Oberon-2 does not use meta-objects, but simply reads from type descriptors compiled into the executable binaries, and exposed in the modules that define the types and/or procedures. If the format of these structures are exposed at the language level (as is the case for Oberon System 3, for example), reflection could be implemented at the library level. It could therefore be implemented almost entirely at library level, without changing the language code. Indeed, Oberon System 3 makes use of language-level and library-level reflection capabilities extensively. HISTORY OF THE OBERON LANGUAGES The original Oberon was designed to be a 'safe' language; it employs array Bounds Checking , Garbage Collection and Strong Type Checking . These features, particularly ones which enable logic errors to be detected as early as possible (i.e. at compile-time), can significantly reduce the number of Bug s occurring in a program at runtime. However, some features included in other languages in an attempt to reduce bugs (e.g. enumerations and programmer-defined ranges on integers), were omitted. Consequently, more care should be taken by the programmer, when working with numeric expressions, to avoid logic errors. Oberon was intended to make mistakes harder in part by making code less opaque, and in part because features not included cannot be misused. This approach can be taken even further, as in APL , which is both exceptionally terse and renowned for being less than easy to understand, but Oberon was deliberately constructed to not oversimplify. As this is an intent whose success cannot be easily quantified, there remains some disagreement that Oberon has achieved its intended goals in this respect. One objection to its strategy of language design simplification was expressed by Jean Ichbiah , the architect of Ada when Wirth criticized Ada for being too big; he responded "There are times when Wirth believes in small solutions for big problems. I don't believe in that sort of miracle. Big problems need big solutions!" Oberon developers have even felt that Oberon went too far in this respect -- Oberon-2 returned the 'FOR' statement to that version of the language. It can be argued that failure to include a feature may force the programmer to reimplement the feature in his code, leading to multiple 'wheel reinvention' and consequent problems. Libraries can mitigate this -- more or less -- effectively depending on the feature and a language's graceful use of such libraries. Java is an example of a relatively simple language (though far less so than Oberon) embedded in large standard libraries. (Oberon has a much smaller standard library than Java.) As much of the effort of learning any language is learning the standard libraries, Ichbiah's objection above can be extended to a strategy of simplification by moving features from the core language into standard libraries. Wirth, and Oberon fans, argue that Oberon has essentially, and effectively, avoided this problem. EXAMPLE OBERON-2 CODE The following Oberon-2 code would implement a simple list class:
ListNode = RECORD value : INTEGER; next : List; END;
BEGIN
END Add;
BEGIN
END AddLast;
BEGIN
END AddAt;
BEGIN
END Remove;
BEGIN
END RemoveLast;
BEGIN
END RemoveAt; END ListClass. FEATURES OF THE ORIGINAL OBERON Key characteristics The following features characterise the Oberon language :
Visibility flags
Local variables, types, constants, and procedures are always visible only to the declaring procedure. Call by reference or by value Two possible modes are available for procedure parameters. Call-by-value (CBV) allows expressions to be used as parameters, so that the value of the expression is passed down to the procedure. Call-by-reference (CBR) allows variables to be used, so that the value of the variable may be changed by the procedure. A procedure may declare a CBR parameter by prefixing it with the VAR keyword.OBERON-2 EXTENSIONS TO OBERON Type-bound procedures Procedures can be bound to a record (or pointer) type. They are equivalent to instance methods in object-oriented terminology. Read-only export The use of exported variables and record fields can be restricted to read-only access. This is shown with a "-" visibility flag. Open arrays Open arrays which previously could only be declared as formal parameter types may now be declared as pointer base types. FOR statement The FOR statement of Pascal and Modula-2 was not implemented in Oberon. It is reintroduced in Oberon-2. Run-time type checking Oberon-2 provides several mechanisms for checking the ''dynamic'' type of an object. For example, where a Bird object might be instantiated to either a Duck or a Cuckoo, Oberon-2 allows the programmer to respond to the actual type of the object at run-time. The first, most conventional, approach is to rely on the type binding system. The second approach is to use the ''' WITH statement''', which allows the dynamic Subtype of a variable to be checked directly. In both cases, once the subtype has been identified, the programmer can make use of any type-bound procedures or variables that are appropriate to the subtype. Examples of these approaches are shown below. Note that the form of WITH statement used in Oberon-2 is unrelated to the Pascal and Modula-2 WITH statement. This method of abbreviating access to record fields is not implemented in Oberon or Oberon-2.Type binding
END; END Birds.
MODULE Ducks; IMPORT Birds;
BEGIN COPY("Quack!", bird.sound); END makeSound; END Ducks.
MODULE Cuckoos; IMPORT Birds;
BEGIN COPY("Cuckoo!", bird.sound); END makeSound; END Cuckoos. WITH statement
VAR sb : SomeBird; VAR c : Cuckoos.Cuckoo; VAR d : Ducks.Duck;
BEGIN WITH bird : Cuckoos.Cuckoo DO bird.sound := "Cuckoo!"; |
|
|