Page 2 of 2

Re: Protected Variables w/in a block.

Posted: Mon May 20, 2013 10:56 am
by MachineCode
langinagel wrote:what is the advantage to use the very same name of a variable in a certain block?
I'd like to know, too. Seems a very weird request to me, unless I'm missing something that makes it essential.

Re: Protected Variables w/in a block.

Posted: Mon May 20, 2013 1:09 pm
by Shield
Well, most of the features are not essential, even Assembly provides way more features
than the bare minimum. It's not about that, it's about giving the programmers more
possibilities to write better code (in terms of readability, maintainability, ...).

On of the reason for scoping is information hiding, being able to define scope local variables
ensures consistency within that scope (no access from outside).
Of course this feature has a much larger effect on module / class scope or even file scope,
PB doesn't support any of those yet.

There is no downside if scopes are supported, none whatsoever. It only has advantages
and makes it easier to write well structured code. If certain people don't care about that,
well...

Re: Protected Variables w/in a block.

Posted: Mon May 20, 2013 2:05 pm
by Little John
Shield wrote:There is no downside if scopes are supported, none whatsoever. It only has advantages
and makes it easier to write well structured code.
The problem seems to be here, that there is no general agreement in this regard. ;-)

E.g.
langinagel wrote:From my point of view it decreases readability and the proper understanding of the code.

Re: Protected Variables w/in a block.

Posted: Mon May 20, 2013 2:14 pm
by Shield
Yes and for some people procedures make the code less readable so they use gosub / goto...

A lot of times people cannot appreciate certain things (classes, modules, type safety, and what not...)
because they don't know how to use them properly or never applied those principles before to be
able to correctly judge them.

I'm not pointing fingers here and frankly I don't really care if PB ever gets those features.
It would be nice for me and for a lot of other guys to see some of the "modern" features
implemented in PB. It's just suggestions that would bring PB a little further ahead.

Of course PB is PB, but there is a reason a vast majority of the most popular languages share
a common set of features: because they work and because they are worth it.

Re: Protected Variables w/in a block.

Posted: Mon May 20, 2013 2:20 pm
by MachineCode
How can protecting a variable inside an If/Then block, and also using the same unprotected variable name outside of that block, be of any practical use? I don't get it. Please show me a practical example (with pseudo-code if necessary) of what it can bring to the table, because my mind obviously can't conceive of the use. :oops:

Re: Protected Variables w/in a block.

Posted: Mon May 20, 2013 2:40 pm
by Shield
For me the major advantage lays in loops, especially 'for' loops,
where I don't want to have the counter variable outside of the loop.
It's also useful for other loops to contain the state completely on
the inside.

Other languages offer closures (basically sub function inside another function that has access to outside variables).
That's another reason why I want to make sure that only a few required variables are visible.

I do agree this is not the *most* useful feature, however it is very useful on module level.

Re: Protected Variables w/in a block.

Posted: Mon May 20, 2013 5:45 pm
by Little John
Shield wrote:It's just suggestions that would bring PB a little further ahead.
Yes, in your opinion. In other people's opinion it would not do so. And claiming that all those people just don't know how to use the proposed feature properly or some such is not based on facts.

Re: Protected Variables w/in a block.

Posted: Tue May 21, 2013 8:31 am
by Shield
I'm not claiming anything, this is just the first obvious thought that pops into my mind
after reading some posts here and there on different forums. :wink:

Re: Protected Variables w/in a block.

Posted: Tue May 21, 2013 10:46 am
by MachineCode
[Never mind]

Re: Protected Variables w/in a block.

Posted: Tue May 21, 2013 10:48 am
by Little John
Shield wrote:I'm not claiming anything, this is just the first obvious thought that pops into my mind
after reading some posts here and there on different forums. :wink:
OK, I see. :-)

Re: Protected Variables w/in a block.

Posted: Tue May 21, 2013 11:18 am
by Shield
Since this might have been understood the wrong way, let me clarify:
It's totally OK not to understand everything (heck, I don't understand anything)
and having an opinion and personal preferences is always good.

However, I noticed often on these forums that people tend to avoid new technologies,
features, ways of doing things, and so on, trying to stick to their old habits and sometimes
fighting furiously against anything that's new or different.

That's what I tried to point out here without explicit relation to this thread.
Nothing more. If that's right or wrong, each person here might judge this by himself / herself.

This is my opinion I dared to share here and anyone else can do so. :)


And now, back to the topic. :)

Re: Protected Variables w/in a block.

Posted: Wed May 22, 2013 2:46 pm
by jassing
Little John wrote:
Shield wrote:It's just suggestions that would bring PB a little further ahead.
Yes, in your opinion. In other people's opinion it would not do so. And claiming that all those people just don't know how to use the proposed feature properly or some such is not based on facts.
Then don't use a feature --- if having a feature meant everyone had to use it; there would be very few features, since not everyone uses every feature... I don't use gosub, but I don't advocate getting rid of them. Local scoping is a fairly common feature; but that doesn't mean you have to use it...

Re: Protected Variables w/in a block.

Posted: Wed May 22, 2013 3:49 pm
by Little John
jassing wrote:
Little John wrote:
Shield wrote:It's just suggestions that would bring PB a little further ahead.
Yes, in your opinion. In other people's opinion it would not do so. And claiming that all those people just don't know how to use the proposed feature properly or some such is not based on facts.
Then don't use a feature --- if having a feature meant everyone had to use it; there would be very few features, since not everyone uses every feature... I don't use gosub, but I don't advocate getting rid of them. Local scoping is a fairly common feature; but that doesn't mean you have to use it...
:?:
Sorry, I don't understand what you want to tell me.
I know that I don't have to use it, and I didn't say that I have to use it.

Re: Protected Variables w/in a block.

Posted: Wed May 22, 2013 7:38 pm
by jassing
Little John wrote: I know that I don't have to use it, and I didn't say that I have to use it.
Just because you can't see the reason for it; doesn't mean it should be denied to those that can see the value in it.

Re: Protected Variables w/in a block.

Posted: Wed May 22, 2013 7:55 pm
by Little John
jassing wrote:Just because you can't see the reason for it
Oh, you believe that I can't see why some people want to get this feature. Interesting.