Re: scope of variables
- Posted by jimcbrown (admin) Dec 30, 2010
- 2837 views
Consistent with what? Procedures and functions are self-contained pieces of code. By enabling variables to be defined with in certain other blocks, those blocks also become self-contained pieces of code. One thing is like the other. Consistent. The only other way to make it consistent is to remove the ability to define variables in a block at all.
Maybe my original example was unclear. Here is another of what I consider to be the proper solution
integer file_log_level = log:WARNING procedure abc() integer abc = 20 -- VALID integer file_log_level = log:ERROR -- INVALID if 10 then integer def -- VALID integer abc -- INVALID end if end procedure
i.e. redefinition of any variable in any child scope is invalid. This is consistent and good practice. There is no reason to redefine file_log_level inside of a procedure or any child scope.
Jeremy
The problem with that is that it could break a lot of pre-existing code. All the way back from the 1.x days.
Since we're post-4.0, we absolutely can not make this change. We can not break existing code.