Re: scope of variables

new topic     » goto parent     » topic index » view thread      » older message » newer message
jaygade said...

I think that it should be changed. The current behavior is inconsistent with other languages and unintuitive. One would expect a block started by a loop or an decision block to work the same as a block defined by a procedure or function.

Changed in what way? There are two possible options here:

integer a = 10 
 
procedure abc() 
    integer a = 20 -- INVALID, a already exists in a containing scope 
end procedure 

and the other change is to make all scopes work like this

integer a = 10 
 
procedure abc() 
    integer a = 20 
    ? a 
end procedure 
 
-- procedure output is 20 

We have to think carefully about this. I'll ask my question again since it seems to be ignored, what is a valid use of redefining a variable in a more narrow scope? In the directly above synario you have now cut off all possibility of accessing the file wide a. Why would you want to do that? Bearing in mind that in a real application there would not be a file wide variable named a, it would be something useful such with a useful name.

For me it seems much more prudent that if there were to be a change the change to be never to allow a variable inside the same namespace to be redeclared. One may say it's heresy, but please tell me why and give valid examples as to why it is necessary to redefine a variable in a more narrow scope to mean something totally different than what it means in a file wide scope.

Jeremy

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu