Modula-3

From Wikipedia, the free encyclopedia

Modula-3
Paradigm: imperative, structured, modular
Appeared in: 1980s
Designed by: DEC and Olivetti
Typing discipline: strong, static
Major implementations: CM3, PM3, EZM3
Dialects: --
Influenced by: Pascal, ALGOL, Modula-2
Influenced: Java, Python, Caml

Modula-3 is a now little-used programming language conceived as a successor to an upgraded version of Modula-2. It was designed by Luca Cardelli, Jim Donahue, Mick Jordan, Bill Kalsow and Greg Nelson at the DEC Systems Research Center and Olivetti in the late 1980s. Its design was heavily influenced by work on the Modula-2+ language in use at DECSRC at the time, which was the language in which the operating system for the DEC Firefly multiprocessor VAX workstation was written. Modula-3's main features are simplicity and safety while preserving the power of a systems-programming language. Modula-3 aimed to continue the Pascal tradition of type safety, while introducing new constructs for practical real-world programming. In particular Modula-3 added support for generic programming (similar to templates), multithreading, exception handling, garbage collection, object-oriented programming, partial revelation and encapsulation of unsafe code. The design goal of Modula-3 was a language that implements the most important features of modern imperative languages in quite basic forms. Thus dangerous and complicating features like multiple inheritance and operator overloading were omitted.

The Modula-3 project started in November 1986 when Maurice Wilkes wrote to Niklaus Wirth with some ideas for a new version of Modula. Wilkes had been working at DEC just prior to this point, and had returned to England and joined Olivetti's Research Strategy Board. Wirth had already moved on to Oberon, but had no problems with the Wilkes' team continuing development under the Modula name. The language definition was completed in August 1988, and an updated version in January 1989. Compilers from DEC and Olivetti soon followed, and 3rd party implementations after that.

During the 1990s, Modula-3 gained considerable currency as a teaching language, but it was never widely adopted for industrial use. Contributing to this may have been the demise of DEC, a key Modula-3 supporter. In any case, in spite of Modula-3's simplicity and power, it appears that there was little demand for a highly structured compiled language with restricted implementation of object-oriented programming. For a time, a closed source compiler called CM3 and integrated development environment called Reactor were offered by Critical Mass, Inc., but that company ceased active operations in 2000. Modula-3 is now no longer taught in universities, and all its textbooks are out of print. Essentially the only corporate supporter of Modula-3 is elego Software Solutions GmbH, which inherited the complete sources from Critical Mass and has since made several releases of the CM3 system in source and binary form. The Reactor IDE could not, however, be released yet by elego due to unclear licensing terms. In March 2002 elego also took over the repository of the last other active Modula-3 distribution, PM3, till then maintained at the École Polytechnique de Montréal.

Contents

[edit] Language features

Exception handling is based on a TRY...EXCEPT block system, which has since become common. One feature that has not been adopted in other languages, with the notable exception of Python[1] and Scala[2], is that the EXCEPT construct defined a pseudo-CASE with each possible exception as a case in one EXCEPT clause. Modula-3 also supports a LOOP...EXIT...END construct that loops until an EXIT occurs, a structure equivalent to a simple loop inside of a TRY...EXCEPT clause.

Object support is intentionally kept to its simplest terms. An object type (class) is introduced with the OBJECT declaration, which has essentially the same syntax as a RECORD declaration, although the type so declared is a reference type, whereas RECORDs in Modula-3 are not (similarly to structs in C). For instance:

A = OBJECT a: INTEGER; METHODS p() := AP; END;

Defines a new object type "A", which contains a single field "a" and method p. The procedure AP that implements p must be defined elsewhere:

PROCEDURE AP(self: A) = BEGIN ... END;

Method calls are accomplished with o.p();, where o is a variable of type A.

Modula-3's REVEAL construct provides a conceptually simple and clean yet very powerful mechanism for hiding implementation details from clients, with arbitrarily many levels of "friendliness".

In summary, the language features:

Modula-3 is one of the rare languages whose evolution of features is documented.

In Systems Programming with Modula-3 four essential points of the language design are intensively discussed. These topics are: Structrual vs. name equivalence, subtyping rules, generic modules, parameter modes like READONLY.

[edit] Syntax

A common example of a language's syntax is the Hello world program.

MODULE Main; 
IMPORT IO;
BEGIN
  IO.Put("Hello World\n")
END Main.

[edit] Implementations

Several compilers are available, most of them open source.

  • DEC-SRC M3, the original
  • Critical Mass CM3, a different successor of DEC-SRC M3
  • Polytechnique Montreal Modula-3 PM3, a successor of DEC-SRC M3, currently merging with CM3
  • EzM3, an independent lightweight and easily portable implementation, developed in connection with CVSup

Since the only aspect of C data structures that is missing from Modula-3 is the union type, all existing Modula-3 implementations are able to provide good binary compatibility with C language type declarations of arrays and structs.

[edit] Books

None of these books are still in print, although used copies are obtainable.

  • Greg Nelson, ed. Systems Programming with Modula-3 The definitive reference on the Modula-3 language with interesting articles on object-oriented systems software construction and a documentation of the discussion leading to the final features of the language.
  • Samuel P. Harbison, Modula-3 Easy to use class textbook.
  • Robert Sedgewick, Algorithms in Modula-3
  • Laszlo Boszormenyi & Carsten Weich, Programming in Modula-3: An Introduction in Programming in Style

[edit] External links

In other languages