ArticleslgStudy

science

Oberon-2

Oberon-2 is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Oberon-2 rather than just read about it. In short: Oberon-2 is an extension of the original Oberon programming language that adds limited reflective programming (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…

Oberon-2 — main illustration
Oberon-2 — illustration

Key takeaways

  • Oberon-2 belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Oberon-2 to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Oberon-2 from memory before moving on to harder problems.

Reference excerpt

Oberon-2 is an extension of the original Oberon programming language that adds limited reflective programming (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, is fully compatible with it, and was a redesign of Object Oberon. Oberon-2 inherited limited reflection and single inheritance ("type extension") without the interfaces or mixins from Oberon, but added efficient virtual methods ("type bound procedures"). Method calls were resolved at runtime using C++-style virtual method tables. Compared to fully object-oriented languages like Smalltalk, in Oberon-2, basic data types and classes are not objects, many operations are not methods, there is no message passing (it can be emulated somewhat by reflection and through message extension, as demonstrated in ETH Oberon), and polymorphism is limited to subclasses of a common class (no duck typing as in Python, and it's not possible to define interfaces as in Java). Oberon-2 does not support encapsulation at object or class level, but modules can be used for this purpose. Reflection in Oberon-2 does not use metaobjects, 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 ETH Oberon, for example), reflection could be implemented at the library level. It could thus be implemented almost entirely at library level, without changing the language code. Indeed, ETH Oberon makes use of language-level and library-level reflection abilities extensively. Oberon-2 provides built-in runtime support for garbage collection similar to Java and performs bounds and array index checks, etc., that eliminate the potential stack and array bounds overwriting problems and manual memory management issues inherent in C and C++. Separate compiling using symbol files and namespaces via the module architecture ensure fast rebuilds since only modules with changed interfaces need to be recompiled. The language Component Pascal is a refinement (a superset) of Oberon-2.

Example code The following Oberon-2 code implements a simple binary tree:

Oberon-2 extensions to Oberon Source:

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 formerly 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.

Runtime 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 runtime. 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

WITH statement

POINTER

IS operator A third approach is possible using the IS operator. This is a relation operator with the same precedence as equals (=), greater (>), etc. but which tests dynamic type. Unlike the two other approaches, however, it does not allow the programmer access to the subtype that has been detected.

Syntax The development of the ALGOL → Pascal → Modula-2 → Oberon → Component Pascal language family is marked by a reduction in the complexity of the language syntax. The entire Oberon-2 language is described (Mössenböck & Wirth, March 1995) using only 33 grammatical productions in the extended Backus–Naur form, as shown below.

… excerpt ends here. Continue reading the full article.

Illustrations

Oberon-2 illustration

Worked examples

Example 1 — a first encounter with Oberon-2

Start with the simplest possible case. Write down what Oberon-2 claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Oberon-2 before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Oberon-2 ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Oberon-2

In research
Oberon-2 appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Oberon-2 in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Oberon-2 is common in secondary-school and first-year university syllabi. It links to neighbouring topics Modula programming language family, Oberon programming language family, Object-oriented programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for Oberon-2 outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Oberon-2” →

How to study Oberon-2 in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Oberon-2 means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Oberon-2 out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Oberon-2 in simple terms?

Oberon-2 is an extension of the original Oberon programming language that adds limited reflective programming (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…

Why does Oberon-2 matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Oberon-2?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Oberon-2.

Tags

  • Modula programming language family
  • Oberon programming language family
  • Object-oriented programming languages
  • Programming languages created in 1991

Keep exploring