[Oberon] Modula2 vs Oberon IMPORT

Duke Normandin dukeofperl at ml1.net
Sat Jan 8 14:36:04 CET 2011


On Sat, 8 Jan 2011, Bob Walkden wrote:

> > Happy New Year Everybody!
> >
> > I see that in Modula only the required procedures are IMPORTed, like:
> >
> > FROM STextIO IMPORT WriteString, WriteLn;
> >
> > Conversely, in Oberon, the whole Module has to be IMPORTed in order to
> > get to use the equivalent procedures.
> >
> > It would seem to me that Oberon "programs" would be that much more
> > "bloated" with unnecessary code. Am I correct in this conclusion? Is
> > there a way to selectively IMPORT procedures in Oberon? It doesn't
> > appear to me to be possible.
>
> In Modula-2 it is implementation-dependent - I don't think the language
> report says anything about it. A clever compiler would only import
> components that were explicitly referenced in the source code
> (cascade-loading dependencies as required); an even cleverer compiler would
> optimise away any unreachable code.

IMHO, "clever" compilers that IMPORT _only_ the required code, is the
ideal situation.

> Qualified import doesn't imply that only the specified components are
> loaded, although it could be used as a compiler hint I suppose. It really
> just gives you the opportunity to obscure your code by not qualifying the
> component idents at the point of use.

Yes! I realized that about qualified IMPORTs - after all, the entire
Module is referenced in the IMPORT statement. Qualified imports simply
allow you to use procedures with the same name, as I understand it.

> With Oberon the components are loaded and unloaded on demand or by the
> garbage collector. In this case qualified import would just be a way of
> avoiding writing the full module name. Oberon gives you a different way of
> obscuring your code by using the rename feature, eg IMPORT Prolixity := P;
> [...] P.Obfuscate; [...].

Yes! Nikitin calls this "aliasing" in his book. Would you explain what
you mean by, "components are loaded and unloaded on demand or by the
> garbage collector." I'm not seeing how that fits in the topic.

> Component Pascal goes even further and lets you ignore part of the module
> name. eg IMPORT StdLog; [....]; Log.Write( ...

My concern is this - if a "main" Module IMPORTS 10 "slave" Modules,
but uses only (e.g.) one procedure from each, then the code bloat in
the final executable would be absurd, would it not? I might as well
cut-n-paste the code into the "main" module, and re-use the code that
way. Maybe this something a "peephole optimizer" could do?

-- 
Duke



More information about the Oberon mailing list