Separate namespace within functions?

"H. Ellenberger" <ele1@gmx.ch>
13 Apr 2003 12:31:41 -0400

          From comp.compilers

Related articles
Separate namespace within functions? ele1@gmx.ch (H. Ellenberger) (2003-04-13)
| List of all articles for this month |
From: "H. Ellenberger" <ele1@gmx.ch>
Newsgroups: comp.compilers
Date: 13 Apr 2003 12:31:41 -0400
Organization: Swisscom IP+ (post doesn't reflect views of Swisscom)
Keywords: design
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
this problem.


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
personnel.


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]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.