[Oberon] Procedure variables and local procedures

Chris Burrows chris at cfbsoftware.com
Sat Sep 30 01:04:48 CEST 2017


> 
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> Claudio Nieder
> Sent: Saturday, 30 September 2017 3:48 AM
> To: ETH Oberon and related systems
> Subject: Re: [Oberon] Procedure variables and local procedures
> 
> I am jumping into the discussion just now, but there is something
> which seems to elude me. So did I understand correctly that a
> procedure can have a nested local procedures but those are not
> allowed to access intermediate variables, but only local and global
> ones?
> 
> If this my understanding is correct, then the question which arises
> is, why are there still local procedures? In my eyes nested
> procedures seem to make only sense to facilitate the access to
> intermediate variables. Eliminating access to intermediate variables
> them to make stuff simple you should also remove nested procedures.

Good question! Nested procedures were absolutely essential for information hiding in original Pascal when all source code was contained in a single program file. Since the time when modules were introduced with Modula-2 the need for nested procedures has diminished. I very rarely use them myself now - whenever I used to use them in Pascal I always seemed to find another place where a nested procedure would be useful and ended up having to make it global anyway.

I am really pleased that intermediate locals are not accessible. The fact that they silently hid a variable with the same name in an outer scope has tripped me up on a number of occasions. Those sorts of issues are hard to find - especially if you did not write the code yourself.

Intermediate variables aren't redundant however. You can still pass them as parameters to the nested procedure if you want to access them. However, by doing that it is more obvious to the code reader what your intention is.

Regards,
Chris Burrows
CFB Software
http://www.astrobe.com/RISC5








More information about the Oberon mailing list