|Separate namespace within functions? email@example.com (H. Ellenberger) (2003-04-13)|
|From:||"H. Ellenberger" <firstname.lastname@example.org>|
|Date:||13 Apr 2003 12:31:41 -0400|
|Organization:||Swisscom IP+ (post doesn't reflect views of Swisscom)|
|Posted-Date:||13 Apr 2003 12:31:41 EDT|
In languages with one huge global name space (e.g. C), it was quite
probable that a variable name local to a function would collide with
an exported name in one of the many #included library files.
Introducing the local name space for functions successfully solved
In languages like Modula-2 where each module has its own name space,
the probability of such name clashes is rather small, so that one
could argument that this local name space is no longer required.
When a local variable name with same name and type like a global
variable is used, everything works ok as long as the local declaration
of the variable is present. In case it unintentionally gets deleted
(slipping to the "delete line" key might do that) the compiler will
still accept the code, but results will no longer be what is expected,
and such an error might be difficult to find for maintenance
What are your pro and cons vs the argument, that for above reasons it
would be better not to have the local name space? (Of course the
local variables would still be locally allocated).
[Misspelled variable names can cause all sorts of program bugs, and
confusing a local and global with the same name is only one of many
ways you can introduce such a bug. -John]
Return to the
Search the comp.compilers archives again.