[Oberon] Intermediate scopes in Oberon-07

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Sat Feb 10 15:37:23 CET 2018


  > One reason why nested procedures still exist may be that they
  > can (sometimes) be used for eliminating problems with forward references.
  > See NWs hint in http://people.inf.ethz.ch/wirth/Oberon/PortingOberon.pdf.

True. However, the case cited in this paper appears to be rather rare in
practice (please correct me if I am wrong) as it works only if one of the
procedures is called *only* from within the other (P and Q in paper). The
general case will typically involve the introduction of procedure variables
anyway. Indeed, the most recent version of the Oberon-07 compiler uses global
procedure variables for “expression”, “Type” and “FormalType”.

After decades of reading compilers *with* forward references *and* the
familiar nested expression-term-factor constructs, I was a bit irritated
at first when I saw this approach, but if one sticks to sensible naming
conventions (e.g. always add a 0), I found it to be acceptable and not
impacting readability. The performance overhead by using procedure variables
(requiring one extra address lookup at run time) seems to be negligible
in this particular case, as most of the time in the compiler is not spent
in procedure activations, but elsewhere.
 

  > One other reason why locally declared constants, types, and procedures
  > still exist may be that
  > there should be some difference to C ;-)

So much for a really good reason ;-) Personally, I believe eliminating
local procedures would not do much harm. It’s one of those things one
might be emotionally attached to a little bit if one was used them for
avery long time - since the Algol days (and even before..). When modules
came along in the 70s, the module took over some benefits previously
associated with local procedures in Pascal (which had only a single
source file, so it made more sense to “structure” the code this way).

In the few cases where it is, perhaps, desirable to nest a procedure
to indicate that it is called only from the enclosing procedure, one
can certainly live with those procedures being global. After all, since
Modula-2 the module is now the unit of information hiding, not the
procedure. Since the programmer is in full control of the module, he
(hopefully) knows when to call a global (not exported) procedure.

AP




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20180210/daed379a/attachment-0001.html>


More information about the Oberon mailing list