From: Mark Hubbart Date: 2005-01-22T04:30:48+09:00 Subject: Re: Confused about variable "declarations" On Fri, 21 Jan 2005 17:25:58 +0900, Robert Klemme wrote: > > "Mark Hubbart" schrieb im Newsbeitrag > news:de63abca0501201148776c2e49@mail.gmail.com... > > On Fri, 21 Jan 2005 02:31:00 +0900, Robert Klemme > wrote: > > > While I completely agree with your explanation the word "leaky" > strikes me > > > as odd as it seems to suggest uncommon or defective behavior: > > > > It wasn't meant to, though I now see why one might take it that way. I > > was using a picture from my mental image of block scope. Not > > everything that leaks is defective; some things are supposed to. I > > would consider a tightly sealed sieve or funnel to be defective :) > > But you wouldn't describe a functioning funnel as "leaky", would you? > Because a leaking funnel is something different - and dangerous, too. :-) lol! point conceded :) > > > it's very > > > common in programming languages, that variables are visible in nested > > > scopes but not surrounding scopes: [...] > > > > I know, but in Ruby, blocks are the only exception to the rule, that I > > know of. Excepting blocks, all scopes are clearly defined, and you > > have to use tricks to access the variables in other scopes. > > IMHO that's only true in Ruby 2.x - not in current versions. The rule for > blocks is the usual rule for nested scopes: if it is defined (in Ruby > "assigned") in a scope then it's visible in all nested scopes from the > definition ("assignment") on but not surrounding scopes. > > > But I'll concede the word "leaky". Perhaps there is a better term for it > :) > > IMHO the usual term of "nested scopes" describes perfectly well, what's > happening here. I'm not quite convinced about that... In other languages that use nested scopes (that I've worked with), variables in the outer scope are accessible, unless you occlude them (yeah, wrong terminology) by declaring a variable with the same name in the inner scope. That creates a new variable to work with for that scope, and leaves the outer one unmodified. And often there are all sorts of rules regarding the persistence of the inner scope variable in case the code in the inner scope is run more than once. IMHO as defining characteristics go, I think that the ability for a nested scope to have it's own variable of the same name as one in the enclosing scope is as important as being able to access the outer scope's variables. I know I just invented several of my own terms, and there were probably some perfectly good terms already defined that would fit what I was talking about. But since I don't know them (I never was a CS major, I'm mostly self-taught) I had to come up with some new ones. Perhaps "nested scopes" is a flexible enough term to handle Ruby's unusual block scope handling as well; but I'm not the one to make full judgement on that. And, regardless, the word I use in my mind when thinking about it will still be "leaky". But with good connotations. :) cheers, Mark