Re: scope of variables
- Posted by jeremy (admin) Dec 30, 2010
- 2891 views
jaygade said...
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