Protected Variables w/in a block.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Protected Variables w/in a block.

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Protected Variables w/in a block.

Post 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...
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Protected Variables w/in a block.

Post 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.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Protected Variables w/in a block.

Post 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.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Protected Variables w/in a block.

Post 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:
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Protected Variables w/in a block.

Post 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.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Protected Variables w/in a block.

Post 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.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Protected Variables w/in a block.

Post 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:
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Protected Variables w/in a block.

Post by MachineCode »

[Never mind]
Last edited by MachineCode on Tue May 21, 2013 10:50 am, edited 1 time in total.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Protected Variables w/in a block.

Post 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. :-)
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Protected Variables w/in a block.

Post 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. :)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Protected Variables w/in a block.

Post 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...
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Protected Variables w/in a block.

Post 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.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Protected Variables w/in a block.

Post 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.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Protected Variables w/in a block.

Post 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.
Post Reply