Oberon Introduction
Volume Number: 13
Issue Number: 3
Column Tag: Tools Of The Trade
Make Way for Oberon/F
By Chad Leigh
Looking for a multi-platform, object oriented framework
and extensible programming environment? Oberon/F might
be the answer
Ever thought about taking a break from the "same old stuff"? Or are you a Pascal
devotee watching the wholesale switch to C and C++? Do you want a development
system that works with and for you instead of you working for it? Looking for an
object oriented framework that is cross-platform? Take a look at the Oberon/F system
from Oberon Microsystems, Inc. of Zürich Switzerland.
Oberon: The Language
The computer language Oberon-2 was developed by Niklaus Wirth (Pascal, Modula-2)
and his associates at the Eidgenössische Technische Hochschule (Swiss Federal
Institute of Technology - abbreviated "ETH") in Switzerland. It was developed, first as
the language Oberon, and later Oberon-2, together with an environment and operating
system also called Oberon. Originally, this was the foundation of the Ceres ETH
workstation. Oberon and its environment have since been ported to many platforms,
including the MacOS, various PC implementations, and a variety of unix machines.
There are commercial versions of the language and environment for many different
computers.
The language Oberon-2 is a compiled, strongly typed, garbage collecting language with
late-binding that is a descendant of Pascal and Modula-2. It is a simple yet powerful
language that provides just the features necessary and no more. It can be used for
structured modular programming as well as for object-oriented programming. Pascal
and Modula-2 programmers can read most Oberon-2 programs without much trouble,
and after a little acquaintance, are soon writing programs of their own. C/C++
programmers must readjust a bit but can soon be using Oberon/F to create their own
components. A good book on object-oriented programming that uses and demonstrates
Oberon-2 is Hanspeter Mössenböck: Object Oriented Programming in Oberon-2,
Springer Verlag, 1993. ISBN 3-540-60062-0.
Oberon (and Oberon/F) is an object oriented language. The language was developed with
the notion of extensibility of software, especially by the user. Extensibility allows a
user to extend the software without having any original source. This is different from
the typical object oriented approach of class libraries where source code often must be
available to the user of the libraries for further inspection and reuse. In Oberon, new
functionality can be added at any time without the original software author's help. New
software is added to or embedded in the user's software to extend its original
functionality. For example, a word processor can have a movie-playing module added
by a different company at a later date without the word processor author having
anything to do with it.
The Oberon/F Implementation of Oberon-2
Oberon/F is an implementation of the Oberon-2 language (called Oberon/L by Oberon
Microsystems in their implementation) consisting of a run-time and development
environment and an object oriented framework (hence the /F). The "look and feel" of
the system and software developed with it is that of the platform. Unlike other Oberon
systems, Oberon/F does not impose its own user interface, and the familiar Mac or
Windows interface is presented to the user. Oberon/F is available for the MacOS and
for 32-bit Microsoft Windows (3.x w/Win32S, W95, NT). A UNIX/Motif version may
be forthcoming. This review deals primarily with the MacOS version. The version
reviewed is developer (commercial) version 1.2.
Oberon/F for Mac requires a MacOS compatible computer with a 68020 processor or
higher or a PowerPC processor. It also requires an FPU or FPU emulator when
running on non-FPU versions of the 68K family as well as on the PPC.[SoftwareFPU
from John Neil works nicely. -ERR ]
Oberon/F on the Macintosh currently compiles 68K code only. Oberon Microsystems
has announced that a PPC compiler should be available later this year. The lack of an
available PPC compiler is unfortunate and I look forward to its arrival.
Oberon/F uses a cross-platform framework for MacOS and Windows built on the
Oberon-2 language. Though it is possible to create large double-clickable applications
with Oberon/F, the emphasis in Oberon/F is on components, not monolithic
applications. Release 1.2 includes its own efficient proprietary component system on
the Mac and includes full support for OLE on Windows. OpenDoc support on the Mac is
promised, and should be available later this year. This means that you can program
your components using Oberon/F and they will automatically work in OLE and OpenDoc.
Oberon Microsystems has also released an Oberon compiler with Direct-to-COM
support for "Safer OLE" on the Windows platform. A Direct-to-SOM Oberon compiler
on the Mac may be in the works, but the exact status of that project is unclear. [By
press time, we were not certain of the status of several of these pending projects, such
as the PPC compiler, the SOM compiler, native OpenDoc, and UNIX implementation.
-ERR ]
Using Oberon/F
There are three general ways Oberon/F can be used on MacOS:
• Use the Oberon/F framework (exclusively) to produce cross-platform software
(components).
• Use straight Oberon-2 language and program the MacOS similarly to the way one
programs the Mac with Pascal or C using toolbox and manager calls.
• Combine the two approaches: use the framework and add new custom framework
modules to take advantage of MacOS specific features that are not in the framework's
built-in functionality, such as QuickDraw GX.
Using The Framework
The Oberon/F framework is modeled on the Models, Views, Controllers (M-V-C)
model from SmallTalk and Xerox PARC. To program in Oberon/F you design your
software so that the data is represented by a set of objects referred to as models. This
data is accessed through views which can represent a given model in different ways.
Manipulating the data is done through a controller object. Different views can access
the same model, and if the model changes, the views are notified to update their
representations.
Abstract sets of layers isolate modules from each other and from the hardware. This
makes it easier to program for extensibility and to support cross-platform
components. The hardware interaction is restricted to low level objects. The basic
Store object represents persistent data on a given medium. This Store object provides
reading and writing functions for mapping data types like integers, characters, etc.
into binary data for storage on a disk or in a file. Models, Views, and Controllers are
extensions of Store objects and are the basic building blocks for writing components in
Oberon/F. The following listing is an example of a simple program that will take the
selected text in the current window and perform a ROT-13 upon it. This program is in
the form of a command which is a parameterless procedure used to extend another
program. This module can be added to any Oberon/F program that runs in the standard
Oberon run-time environment and that uses the standard Oberon/F framework
subsystem called Text (or an extension of this subsystem). [A ROT-13 jumbles and
unjumbles text. It is used by Usenet groups to hide the text from casual observers.
-ERR ]
The program imports only those modules it will use, such as the Text subsystem.
Inside our Do procedure we declare a controller, tc, a text reader, tr, a writer, tw,
and a model, buf. We also declare some helper variables to represent the beginning and
ending locations of the selected text and to hold the current. The script is a special
object that allows us to easily implement undo/redo functionality. We first set up our
controller to point to the currently focused window. If it exists and has a selection then
we get that selection and set our beginning and ending helper variables. We then
instantiate a new writer for our model, buf, as well as a reader. Then we iterate over
our selected text and do our ROT-13 operation. As we operate on each character, we
save it to our model. After traversing the selection and building a new ROT-13 version
in our local model, we copy it to our original text item and replace the original with
the new version. The end result is that the original selection in our text window at
command execution is now mixed up by a ROT-13 operation.
Listing 1.
MactechRot13
(* This Module is a sample using the Oberon/F framework. It performs a
ROT-13 on the current text selection.
This module can be added to any program that uses the text subsystem.
PROCEDURE Do is a parameterless
procedure called a "command." This is a complete module and can be
compiled by itself. *)
MODULE MactechRot13;
IMPORT Models, TextModels, TextControllers, Domains;
PROCEDURE Do*;
VAR tc: TextControllers.Controller;
beg, end: LONGINT;
tr: TextModels.Reader;
ch: CHAR;
buf: TextModels.Model;
tw: TextModels.Writer;
script: Domains.Operation;
BEGIN
tc := TextControllers.Focus();
IF (tc # NIL) & tc.HasSelection() THEN
tc.GetSelection(beg, end);
buf := TextModels.Clone(tc.text);
tw :=buf.NewWriter(NIL);
tr := tc.text.NewReader(NIL);
tr.SetPos(beg);
tr.ReadChar(ch);
WHILE (tr.Pos() <= end) & ~tr.eot DO
IF ((ch >= "a") & (ch <= "m")) OR
((ch >= "A") & (ch <= "M")) THEN
ch := CHR(ORD(ch)+13);
ELSIF ((ch >= "n") & (ch <= "z")) OR
((ch >= "N") & (ch <= "Z")) THEN
ch := CHR(ORD(ch)-13)
END;
tw.WriteChar(ch);
tr.ReadChar(ch)
END;
Models.BeginScript(tc.text, "Rot13", script);
tc.text.Delete(beg, end);
tc.text.CopyFrom(beg, buf, 0, end - beg);
Models.EndScript(tc.text, script)
END
END Do;
END MactechRot13.
The Oberon/F framework as shipped includes two subsystems that can be used and
extended. These are the Text and the Forms subsystems. Oberon Microsystems, Inc. and
third parties are releasing (or will release in the future) other subsystems including
database access, high precision math, and others. For example, the Sql subsystem was
recently released and is a full featured SQL access subsystem that comes with the dtF
SQL database system.
The Text subsystem provides basic formatted text services, similar to TextEdit. It
includes styled text and other basic word processor features. The Oberon/F
development environment itself relies heavily on the Text subsystem. Most programs
will probably rely on the Text subsystem or on developer extensions to this subsystem
for their text processing.
The Forms subsystem allows easy development of user interface with dialogs and
similar "form-like" objects. Each element in a given form is directly linked to an
Oberon program variable. For example, a button may be linked to a boolean, a text
field to a string, etc. When a user manipulates a button or types in the text field, the
variable is automatically updated. Oberon/F also includes a visual interface designer to
interactively build and test "forms.
Figure 1. The forms subsystem links automatically to variables. There is a wide
variety of graphical elements that can be placed in a form.
Oberon/F For Traditional MacOS Programming
Oberon/F can be used for its Oberon-2 language implementation alone to program
traditional MacOS applications. In this scenario, the software developer controls and is
responsible for everything, just as when using C/C++ or Pascal. The standard event
loop must be supported, all managers must be properly initialized, and all other
housekeeping chores must be completed.
It is very easy to do traditional Mac programming with Oberon/F. If you already use
Pascal, then switching to Oberon/F is a snap, as the languages are very similar and
were invented by the same person. C programmers should also have little trouble once
they shift into gear. Using the object oriented features of Oberon/F greatly expands the
ability of the software developer to write robust software in a simple and maintainable
way. With the garbage collection feature of the language, gone are many of the "Bus
Errors" and memory leaks that so often afflict software written in other languages.
When using Mac specific data structures you must manage memory yourself, because
Mac specific data structures used by the OS and the Toolbox lie outside the reach of the
Oberon runtime system and cannot use garbage collection services. However, your
application's own data structures can take full advantage of Oberon's features including
garbage collection, and there are some techniques that allow you to take full advantage
of garbage collection for your data structures that are referenced by the Mac. For
example, using a window refCon is often used to keep an object pointer so that actions
on windows can be done through a window's object passed back to the program.
However, the Oberon system is not aware that your window record maintains a link to
your object and so will garbage collect your window object when your application is
not using it. The Oberon system is not usually in control of your window record,
because it is a Mac data structure. Alternatively, you can keep a separate list of
window objects, or you can have the window object keep a reference to itself. By
referencing itself, the garbage collector knows that the object still has outstanding
references and will not dispose of it until you set the self reference to nil.
Many standard MacOS traps and routines are all available to the Oberon programmer
out of the box. This latest release of Oberon/F, V1.2, also gives us some automatic
AppleScript support. The DoEvent Apple event allows one to execute any command (or
parameterless procedure) externally through AppleScript or other AppleEvent aware
application.
Each separate manager has its own MODULE defined for it. Some managers such as