Re: scope of variables
- Posted by coconut Dec 30, 2010
- 2831 views
It occurs to me that the current behavior is inconsistent with respect to forward referencing.
You can't forward reference inside a procedure.
You can do this at the file level.
This breaks:
procedure x() b = 1 integer b end procedure
This works:
procedure x() b = 1 end procedure x() integer b
But this breaks:
b = 1 integer b
It does seem like routine-scopes are already handled specially. Maybe we can contiue to justify the special treatment of routine-scopes (backwards compatible symbol shadowing remains supported) while changing the rest (so integer b...for...integer b...end for and for...integer b...end for..integer b both break).
On the other hand, it might be easier to make all scoping rules apply equally to all the different scopes.
I was thinking that forward reference was applied to functions and procedures only not variables. This is more complex than I though at first...
So Jeremy want to remove the opportunity to redeclare a variable inside a procedure even though we can access the top level one by namespace qualifier. This would surely brake some of my code. Jeremy is suggesting an opting out with
without strict_naming -- if this is adopted it should be clearely mentioned that it should be used only for backward compatiliby. --
I could leave with it as long as the scoping rules are pervasive to all scopes. One rule for all this is democracy This will depart from other languages but as somenone said it is not nature rules.
Better to take the time to think it well.
Jacques