Lawrie Schonfelder <[log in to unmask]> wrote:
...
>On Thu, 10 Aug 2000 09:43:14 +0100 (BST) Malcolm Cohen <[log in to unmask]>
>wrote:
>
>snip....
>
>> If one is going to make constructs effectively into scoping units, one
>> might as well go whole hog and allow them to have declarations of variables
>> local to the construct.
>>
>
>Hear! Hear! Now that would be a truely great idea and only about 40 years
>after the concept was invented!
It's an awful lot of work, for the committee and implementors,
for very little benefit. In those languages that permit such
declarations, programmers almost never use them. I think
this is because in short procedures it's unnecessary and in
long procedures it's confusing. The examples that people
use to promote the feature are atypical of how the feature
gets used (and abused), if at all.
Having said that, I still think that the feature might be useful
as a minor convenience - but not as usually described. First,
I think it's a bad idea to use blocks whose purpose is control
flow. A block that introduces new scope should be recognizably
different from other blocking constructs. Fortran doesn't use
the BEGIN keyword anywhere. Why not have BEGIN-END
blocks for nested scope? This eliminates some of the confusion
that often arises since it's no longer possible to bury a declaration
in the middle of your code without calling attention to it.
Second, I think the usually described functionality is incomplete.
It only allows declarations of new items of limited scope and the
redeclaration of items from outside. It does not allow excluding
items from the outside scope that you *know* that the code
cannot define or reference. So, we could allow the USE ...,ONLY
construct to serve that purpose:
construct_name: BEGIN
USE , ONLY A,B,C
... other declarations ...
... code ...
END construct_name
The USE without a module name would refer to the host scoping
unit. Note that this form of USE would be valuable for internal
procedures as well. (Note also that I believe that construct_name
should not be optional for these blocks.)
Even with these changes, the proposal is only of very minor
importance. I suspect that the language will never contain
any version of it.
--
J. Giles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|