Cases are always helpful... thanks...
> now when declaring the intermediate x as local:
> =============================
> Foo()
> {
> int x = 1;
>
> bar() {
> local int x=5;
> print( x ); // #1
>
> { // Inner scope
> print( x ); // #2
> }
> }
>
> Bar();
> print( x ); // #3
> return this;
> }
> Foo myFoo = Foo();
> print( myFoo.x ); // #4
> ==========================
> #1 should print 5
> #2 should it print 1 because x=5 is local to its scope?
I would suggest not for two reasons (below)
First, the primary thing at issue right now is that in this case there are two
variables (since you declared each with a type "int" each time).
But on the access issue...
#1) Just FYI - The anonymous block you have declared there already acts in the
way that we are proposing because it's just a block. If you said "x=6;" there
it would be just as if you had assigned it in the scope above. In bsh as in
Java unqualified variable assignments in a block act just like they are part
of the enclosing scope. However if you allocate a new variable there
(int x=6;) it will not appear outside of the block. So our proposal will
just make the rest of Bsh's scoping (method scoping) consistent with this/Java.
But to address your point about access modifiers just make it a new nested
method... then...
#2) I think the answer is to act as Java does in the class/method context...
private int x = 5; would be visible to scopes "below/inside" of that
scope int the same way that private instance variables are visible to
methods in the class body. Anything else seems a bit hard to swallow to
me...
...
So, I'm leaning towards 'var' with a switch to disable it for backwards
compatability... still keeping an open mind though.
Thanks,
Pat

Community

Help

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

CountryState

JavaScript is required for this form.

I agree to receive quotes, newsletters and other information from sourceforge.net and its partners regarding IT services and products. I understand that I can withdraw my consent at any time. Please refer to our Privacy Policy or Contact Us for more details