Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-24-2009, 10:36 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Private variables

Support for protected and private variables would be very nice, even if only added serverside.

PHP Code:
function setVars() {
  private 
this.foo "bar";
  protected 
this.var = "str";

Other scripts could access "this.var", but not edit it. Other scripts would have absolutely no indication that "this.foo" even existed.

I'm pretty sure this has been requested before, but it still hasn't been added
__________________
Reply With Quote
  #2  
Old 05-04-2009, 05:58 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
bump
__________________
Reply With Quote
  #3  
Old 05-04-2009, 01:59 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
I agree, would be a nice addition.
Reply With Quote
  #4  
Old 05-04-2009, 03:12 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
I support this!
__________________
Reply With Quote
  #5  
Old 05-04-2009, 03:54 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
I think private variables would be better implemented as some sort of prefix like __ rather than as a keyword. this.pr_blah would be private or so.

Edit: I like this.__blah__ better
__________________

Last edited by Inverness; 05-04-2009 at 04:56 PM..
Reply With Quote
  #6  
Old 05-04-2009, 03:57 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Good idea, I totally support.

Quote:
Originally Posted by Inverness View Post
I think private variables would be better implemented as some sort of prefix like __ rather than as a keyword. this.pr_blah would be private or so.
Why?
Reply With Quote
  #7  
Old 05-04-2009, 04:10 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
I think they would fit good as keywords, such as const
__________________
Reply With Quote
  #8  
Old 05-04-2009, 04:16 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Chompy View Post
I think they would fit good as keywords, such as const
I agree
Reply With Quote
  #9  
Old 05-04-2009, 04:19 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by cbk1994 View Post
Other scripts would have absolutely no indication that "this.foo" even existed.
What would happen if some other script tried to set it?
Reply With Quote
  #10  
Old 05-04-2009, 04:52 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Codein View Post
Why?
Graal is highly dynamic language, I don't think it's a good idea to have private variables unless there is easy to tell the access level of any variable.
Quote:
Originally Posted by Chompy View Post
I think they would fit good as keywords, such as const
const is not part of GScript itself, they are resolved by the compiler, similar to a macro in C.

Making changes to a language syntax is something that requires alot of thought, and I'm annoyed with the lack of it right now.
__________________
Reply With Quote
  #11  
Old 05-04-2009, 05:03 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Inverness View Post
Graal is highly dynamic language, I don't think it's a good idea to have private variables unless there is easy to tell the access level of any variable.
Hrm, I can see what you mean. However, I don't agree that the 'pr_' prefix is the best way to DECLARE a private variable.

Maybe something like this:

PHP Code:
private this.pr_var "redfish"
Where the keyword actually declares the variable as private, and the name indicates that it is a private variable, as some sort of convention maybe.

I think indicating what's private and what's not should be completely down to the programmer.
Reply With Quote
  #12  
Old 05-04-2009, 05:16 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by Inverness View Post
Graal is highly dynamic language, I don't think it's a good idea to have private variables unless there is easy to tell the access level of any variable.
I do not see what being dynamic has to do with anything. In Ruby, which is dynamic as ****, every member variable is private.

Quote:
const is not part of GScript itself, they are resolved by the compiler, similar to a macro in C.
By that logic, C has no language features since they are all resolved by the compiler to assembly.

Quote:
Making changes to a language syntax is something that requires alot of thought, and I'm annoyed with the lack of it right now.
Just give us Scheme macros so we do not have to bug Stefan to change the syntax for us.
Reply With Quote
  #13  
Old 05-04-2009, 05:17 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Codein View Post
Hrm, I can see what you mean. However, I don't agree that the 'pr_' prefix is the best way to DECLARE a private variable.

Maybe something like this:

PHP Code:
private this.pr_var "redfish"
Where the keyword actually declares the variable as private, and the name indicates that it is a private variable, as some sort of convention maybe.

I think indicating what's private and what's not should be completely down to the programmer.
I am 100 percent against a private keyword. Graal is too dynamic to have variable behavior changed by keywords.

I think this.__var (or this.__var__) is a much better way of indicating a private variable, because you can simply look at it and know that it's private without having to use a function to check the access level.

A great many scripters on Graal don't understand the importance of convention in a scripting language and Stefan makes no effort to try to enforce one. So even if you propose a convention it will most likely not be upheld and everyone will just indicate private variables however they please. My proposition forces scripters to name the variable a specific way if they want the functionality. You're defeating yourself with your own argument's complexity, simple is better.

Edit: Also, isn't it rather redundant to have both the keyword and the convention? If you're wanting everyone to use pr_ to indicate private variables, why not simply make that the way to declare them? That way you don't need to make a more complicated change to GScript by introducing access level keywords.
Quote:
Originally Posted by Loriel View Post
I do not see what being dynamic has to do with anything. In Ruby, which is dynamic as ****, every member variable is private.
Well if every member variable is private you don't need a private keyword then.
Quote:
Originally Posted by Loriel View Post
By that logic, C has no language features since they are all resolved by the compiler to assembly.
I'm saying that const is a compiler feature, not really a feature of GScript. With the proposed access level keyword, that would not be the case. So you can't say private would fit good with keywords such as const, because const isn't part of GScript, and an access level constraint certainly is.

Edit2: I just noticed I reached 3,000 posts, yay me.
__________________

Last edited by Inverness; 05-04-2009 at 05:32 PM..
Reply With Quote
  #14  
Old 05-04-2009, 05:53 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Inverness View Post
I am 100 percent against a private keyword. Graal is too dynamic to have variable behavior changed by keywords.

I think this.__var (or this.__var__) is a much better way of indicating a private variable, because you can simply look at it and know that it's private without having to use a function to check the access level.

A great many scripters on Graal don't understand the importance of convention in a scripting language and Stefan makes no effort to try to enforce one. So even if you propose a convention it will most likely not be upheld and everyone will just indicate private variables however they please. My proposition forces scripters to name the variable a specific way if they want the functionality.

Edit: Also, isn't it rather redundant to have both the keyword and the convention? If you're wanting everyone to use pr_ to indicate private variables, why not simply make that the way to declare them? That way you don't need to make a more complicated change to GScript by introducing access level keywords.
Yeah, I can see exactly what you mean. However, I still think a keyword would still be best. I mean, I have, for some time, wanted some kind of support for classes, in a traditional sense and keywords for declaring class members would be necessary in my opinion.

Also, I don't see you preaching conventions, being in a position of influence within the scripting community. If you shown the importance of them, like many other of the Scripting Elite on here, there should be an improvement in that field.

Regarding your edit, the convention is optional, as with any convention. It's just recommended. There's something about using what LOOKS like a convention as an actual declaration gets to me, for some reason.

However, I'd just like to see private variables. If Stefan agrees with you, I'm not really bothered, as such. It still does what I want.
Reply With Quote
  #15  
Old 05-04-2009, 06:08 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Codein View Post
Yeah, I can see exactly what you mean. However, I still think a keyword would still be best. I mean, I have, for some time, wanted some kind of support for classes, in a traditional sense and keywords for declaring class members would be necessary in my opinion.
Python is a very popular language and it implements classes just fine without variable access keywords. Something like private variables are implemented using name mangling with variables prefixed with '__', __e becomes __Pancake_e where Pancake is the name of the class, avoiding collision by inheritance. There isn't an absolute way to prevent variable access and I don't think one is necessary in Python or Graal.
Quote:
Originally Posted by Codein View Post
Also, I don't see you preaching conventions, being in a position of influence within the scripting community. If you shown the importance of them, like many other of the Scripting Elite on here, there should be an improvement in that field.
I'm not a miracle worker. I also don't care too much about what other people do as long as I don't have to look at their scripting. And I think you overestimate my influence.
Quote:
Originally Posted by Codein View Post
Regarding your edit, the convention is optional, as with any convention. It's just recommended. There's something about using what LOOKS like a convention as an actual declaration gets to me, for some reason.
With Graal scripters it's much better to force them to do it a certain way, they just don't follow convention.
__________________
Reply With Quote
  #16  
Old 05-04-2009, 06:37 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Inverness View Post
Python is a very popular language and it implements classes just fine without variable access keywords. Something like private variables are implemented using name mangling with variables prefixed with '__', __e becomes __Pancake_e where Pancake is the name of the class, avoiding collision by inheritance. There isn't an absolute way to prevent variable access and I don't think one is necessary in Python or Graal.
Haha, I knew Python was going to come up one time or another in this topic

The thing is in other scripting languages, such as PHP, keywords are used and work fine and I actually PREFER them. It makes it much much clearer to see how certain variables are declared and how they should be used, looking through a script. That, COUPLED with the convention, it's a winner, in my opinion.

Can you explain how Graal is TOO dynamic for keywords? How have you come to that conclusion?

Quote:
Originally Posted by Inverness
I'm not a miracle worker. I also don't care too much about what other people do as long as I don't have to look at their scripting. And I think you overestimate my influence.
Aye, you're not a miracle worker. It also disppoints me to hear your lack of consideration and interest in up and coming scripters.

Overestimating your influence? You've had influence over MANY a scripter. Maybe you're blind to this, because of your lack of consideration for new scripting talent, maybe?

Quote:
Originally Posted by Inverness
With Graal scripters it's much better to force them to do it a certain way, they just don't follow convention.
I don't think taking a forced approach is the best way. Many scripters, after a while of scripting, explore other languages. They need to learn that, although optional, convention is still important.
Reply With Quote
  #17  
Old 05-04-2009, 08:10 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Codein View Post
The thing is in other scripting languages, such as PHP, keywords are used and work fine and I actually PREFER them. It makes it much much clearer to see how certain variables are declared and how they should be used, looking through a script. That, COUPLED with the convention, it's a winner, in my opinion.
PHP is not used the way GScript is, Graal is a constantly changing environment and GScript is equipped to deal with it dynamically.
Quote:
Originally Posted by Codein View Post
Can you explain how Graal is TOO dynamic for keywords? How have you come to that conclusion?
Objects and their variables are often serialized and deserialized as "varname=value". This format is not equipped for specifying the access level of variables. If the access level was dependent on the variable name, no changes would be required for any of this.
Quote:
Originally Posted by Codein View Post
Aye, you're not a miracle worker. It also disppoints me to hear your lack of consideration and interest in up and coming scripters.
I'd be more interested if Graal was actually updated with the variety of features scripters have been suggesting for months and years.
Quote:
Originally Posted by Codein View Post
Overestimating your influence? You've had influence over MANY a scripter. Maybe you're blind to this, because of your lack of consideration for new scripting talent, maybe?
Ever since I moved on into the world of C/C++, Python, and Lua I've grown to dislike GScript because of its inconsistency among other things. It doesn't inspire me to help with new scripting talent or such things.
Quote:
Originally Posted by Codein View Post
I don't think taking a forced approach is the best way. Many scripters, after a while of scripting, explore other languages. They need to learn that, although optional, convention is still important.
Convention can be taught with other means rather than with something so important as private variables.


Let's break it down:

To implement my suggestion, Stefan would need to implement a fix to the variable set and get functions in Graal so that if you're getting a variable that starts with __ from something other then yourself then you get denied.

To implement your suggestion, Stefan would need to modify the compiler to recognize variable access keywords, add functions for getting the access level from variables. Since I doubt changes would be done to save file format, you would only be able to load private variables into an object if the variable already exists and has been declared private, or you could possibly set a private prefix for the load function, which ends up doing what my suggestion would do automatically. And depending on how it's done, all objects would have an increased (minor) memory footprint so variables can store their access level. If you want to avoid that then you'd need an array or hash table of private variable names which would just make variable access slower.
__________________
Reply With Quote
  #18  
Old 05-04-2009, 08:24 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Taking into account the way variables are serialised, I think your way would be the better way to implement, yeah.

Last edited by Codein; 05-04-2009 at 08:52 PM..
Reply With Quote
  #19  
Old 05-05-2009, 12:14 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
From my thread on this, http://forums.graalonline.com/forums...ad.php?t=71199

Stefan originally suggested the possibility of thisr. or this.protected.whatevs
Reply With Quote
  #20  
Old 05-05-2009, 03:45 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Twinny View Post
From my thread on this, http://forums.graalonline.com/forums...ad.php?t=71199

Stefan originally suggested the possibility of thisr. or this.protected.whatevs
I think it is better to have the indicator in the variable name because of the reasons I mentioned above, imho. thisr. isn't really part of the variable name.
__________________
Reply With Quote
  #21  
Old 05-17-2009, 02:23 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
bump
__________________
Reply With Quote
  #22  
Old 06-18-2009, 03:37 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
bump
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:35 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.