Objects as Modules in Newspeak

Objects as Modules in Newspeak, by Gilad Bracha et al.
We describe support for modularity in Newspeak, a new programming language descended from Smalltalk and Self. Like Self, all computation — even an object’s own access to its internal structure — is performed by invoking methods on objects. However, like Smalltalk, Newspeak is class-based. Classes can be nested arbitrarily, as in Beta. Since all names denote method invocations, all classes are virtual; in particular, superclasses are virtual, so all classes act as mixins. Unlike its predecessors, there is no static state in Newspeak, nor is there a global namespace. Top level classes act as module definitions, which are independent, immutable, self-contained parametric namespaces. They can be instantiated into modules which may be stateful and mutually recursive. Naturally, like its predecessors, Newspeak is reflective: a mirror library allows structured access to the program meta-level.
A simple, principled, and intriguing language design.

Decades ago, one of the major advances in programming language design was the claim that programming-in-the-small and programming-in-the-large require different constructs. Newspeak (along with Scala) reverses this trend, claiming classes are a good fit for both.

Type families represent a key example of program structuring that is difficult to support with current type systems (see, e.g., 'A statically safe alternative to virtual types' Kim B. Bruce, Martin Odersky, and Philip Wadler, ECOOP 1998). Newspeak, by virtue of using late binding everywhere and having no type system, supports type families easily. Thus, I view Newspeak as posing a key question: what is the type system that will support type families as elegantly as Newspeak?

Newspeak's innovation of prohibiting a global namespace is also interesting. Although Newspeak is very much an imperative language, this aspect is right in line with functional languages, as it argues that sometimes making a dependency painfully explicit is the better course, as it supports parameterization and reuse. In particular, this provides a simple and principled solution to the same problems tackled by complex frameworks for dependency injection.

As I commented on Gilad's blog when he posted about this earlier, Scala can represent first class recursive modules in much same style as Newspeak.

His main objection seems to be that Scala also supports packages and imports as well. Given that this is pretty much essential for Scala's Java compatibility I don't see this as a deficiency.

Thanks for the kind words! Indeed, typing Newspeak is an interesting challenge. Also, while Newspeak is imperative, the ideas apply to functional languages as well.

Miles: Scala's imports, packages and constructors are not necessary to interoperate with Java; they are a path of least resistance, but one could do without them.

Of course, doing things the Newspeak way does raise additional typing challenges, as Phil notes.
It's been my experience, in all languages concerned, that the failure to distinguish modules from classes or objects results in severe difficulties when applied towards large- or enterprise-scale application development. I'm not really smart enough to figure out why this is, but the paper Import Is Not Inheritance by Szyperski seems to explain it better than I can.
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?