www.digitalmars.com         C & C++   DMDScript  

D - readonly variables

reply imr1984 <imr1984_member pathlink.com> writes:
ok so currently when people want a class member variable they dont want anyone
to mess with, they create the variable with a preceeding underscore and then
create a read only property for it. So most of the time properties are
unnesesary and a simple readonly variable would do. something like this:

readonly int myVariable;

instead of:

private int _myVariable;
int myVariable() {return _myVariable;}

i hope walter considers this, because it would save time
Feb 15 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
imr1984 wrote:

ok so currently when people want a class member variable they dont want anyone
to mess with, they create the variable with a preceeding underscore and then
create a read only property for it. So most of the time properties are
unnesesary and a simple readonly variable would do. something like this:

readonly int myVariable;

instead of:

private int _myVariable;
int myVariable() {return _myVariable;}

i hope walter considers this, because it would save time

  

out int myVariable; //Readonly in int myVariable2; //Writeonly inout int myVariable2; //Default -- -Anderson: http://badmama.com.au/~anderson/
Feb 15 2004
prev sibling next sibling parent reply "Ben Hinkle" <bhinkle4 juno.com> writes:
"imr1984" <imr1984_member pathlink.com> wrote in message
news:c0nvjl$1794$1 digitaldaemon.com...
| ok so currently when people want a class member variable they dont want anyone
| to mess with, they create the variable with a preceeding underscore and then
| create a read only property for it. So most of the time properties are
| unnesesary and a simple readonly variable would do. something like this:
|
| readonly int myVariable;
|
| instead of:
|
| private int _myVariable;
| int myVariable() {return _myVariable;}
|
| i hope walter considers this, because it would save time

What about other the protection attributes? The meaning of a
"readonly" attribute overlaps with the protection attribute.
What does something like

 readonly public int myVariable;

declare? Or, similarly, what about

 readonly private int myVariable;

Any attribute that controls read/write access needs to spell out
how it interacts with the protection attributes. Perhaps some
fancy protection attribute syntax would be better than a separate
attribute - not that I can think of any good suggestions.

-Ben
Feb 15 2004
next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Ben Hinkle wrote:

"imr1984" <imr1984_member pathlink.com> wrote in message
news:c0nvjl$1794$1 digitaldaemon.com...
| ok so currently when people want a class member variable they dont want anyone
| to mess with, they create the variable with a preceeding underscore and then
| create a read only property for it. So most of the time properties are
| unnesesary and a simple readonly variable would do. something like this:
|
| readonly int myVariable;
|
| instead of:
|
| private int _myVariable;
| int myVariable() {return _myVariable;}
|
| i hope walter considers this, because it would save time

What about other the protection attributes? The meaning of a
"readonly" attribute overlaps with the protection attribute.
What does something like

 readonly public int myVariable;

declare? Or, similarly, what about

 readonly private int myVariable;

Any attribute that controls read/write access needs to spell out
how it interacts with the protection attributes. Perhaps some
fancy protection attribute syntax would be better than a separate
attribute - not that I can think of any good suggestions.

-Ben
  

int myVariable {return myVariable;} Where myVariable is created implicitly. This code would be executed inside and outside the class for myVariable however the variable would only be changeable from within the class. It wouldn't completely solve the private situation but at least the code is still used in private situations. -- -Anderson: http://badmama.com.au/~anderson/
Feb 15 2004
parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:c0oh8p$22ea$1 digitaldaemon.com...
 Ben Hinkle wrote:

"imr1984" <imr1984_member pathlink.com> wrote in message


| ok so currently when people want a class member variable they dont want


| to mess with, they create the variable with a preceeding underscore and


| create a read only property for it. So most of the time properties are
| unnesesary and a simple readonly variable would do. something like


|
| readonly int myVariable;
|
| instead of:
|
| private int _myVariable;
| int myVariable() {return _myVariable;}
|
| i hope walter considers this, because it would save time

What about other the protection attributes? The meaning of a
"readonly" attribute overlaps with the protection attribute.
What does something like

 readonly public int myVariable;

declare? Or, similarly, what about

 readonly private int myVariable;

Any attribute that controls read/write access needs to spell out
how it interacts with the protection attributes. Perhaps some
fancy protection attribute syntax would be better than a separate
attribute - not that I can think of any good suggestions.

-Ben

int myVariable {return myVariable;} Where myVariable is created implicitly. This code would be executed inside and outside the class for myVariable however the variable would only be changeable from within the class. It wouldn't completely solve the private situation but at least the code is still used in private situations.

Or, what about private int _myVariable; public int myVarable { return _myVariable }; ? :)
Feb 15 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Matthew wrote:

What about

int myVariable {return myVariable;}

Where myVariable is created implicitly.  This code would be executed
inside and outside the class for myVariable however the variable would
only be changeable from within the class.  It wouldn't completely solve
the private situation but at least the code is still used in private
situations.
    

Or, what about private int _myVariable; public int myVarable { return _myVariable }; ? :)

be fixed for readonly. -- -Anderson: http://badmama.com.au/~anderson/
Feb 15 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:c0oicd$23pj$3 digitaldaemon.com...
 Matthew wrote:

What about

int myVariable {return myVariable;}

Where myVariable is created implicitly.  This code would be executed
inside and outside the class for myVariable however the variable would
only be changeable from within the class.  It wouldn't completely solve
the private situation but at least the code is still used in private
situations.

Or, what about private int _myVariable; public int myVarable { return _myVariable }; ? :)

be fixed for readonly.

Nah! I was just being a witless smartarse. My point was that it's so easy to do what the OP wanted with the code he gave that there's little motivation to complicate the language by adding the posited keyword
Feb 15 2004
prev sibling parent reply imr1984 <imr1984_member pathlink.com> writes:
yeah something like that. all im saying is that the current method of creating
access properties for member variables is a waste of time, AND it leads to ugly
underscores around the place which makes it look hungarian. And if im not
mistaken Walter hates hungarian :)

In article <c0ofel$1vnb$1 digitaldaemon.com>, Ben Hinkle says...
"imr1984" <imr1984_member pathlink.com> wrote in message
news:c0nvjl$1794$1 digitaldaemon.com...
| ok so currently when people want a class member variable they dont want anyone
| to mess with, they create the variable with a preceeding underscore and then
| create a read only property for it. So most of the time properties are
| unnesesary and a simple readonly variable would do. something like this:
|
| readonly int myVariable;
|
| instead of:
|
| private int _myVariable;
| int myVariable() {return _myVariable;}
|
| i hope walter considers this, because it would save time

What about other the protection attributes? The meaning of a
"readonly" attribute overlaps with the protection attribute.
What does something like

 readonly public int myVariable;

declare? Or, similarly, what about

 readonly private int myVariable;

Any attribute that controls read/write access needs to spell out
how it interacts with the protection attributes. Perhaps some
fancy protection attribute syntax would be better than a separate
attribute - not that I can think of any good suggestions.

-Ben

Feb 15 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
 yeah something like that. all im saying is that the current method of

 access properties for member variables is a waste of time,

I think you're overstating the case somewhat
 AND it leads to ugly
 underscores around the place which makes it look hungarian.

I don't look at underscores and see Hungarian. Sorry
 And if im not
 mistaken Walter hates hungarian :)

He does My point is that this is something that's *easily* handled within the current faculties of the language. Adding new keywords is a very big deal, and it has to add very significant utility, that would otherwise be impossible, or require huge amounts of effort. typeof is a perfect example of something that should be a keyboard. TMP attributes, such as is_pod, is_scalar, etc. are also likely to fall into this category. Your requirement for readonly is understandable and nice, but it's just not sufficiently difficult to implement your requirements for it to represent much of an incentive unless other congruent uses for the keyboard are identified.
 In article <c0ofel$1vnb$1 digitaldaemon.com>, Ben Hinkle says...
"imr1984" <imr1984_member pathlink.com> wrote in message


| ok so currently when people want a class member variable they dont want


| to mess with, they create the variable with a preceeding underscore and


| create a read only property for it. So most of the time properties are
| unnesesary and a simple readonly variable would do. something like


|
| readonly int myVariable;
|
| instead of:
|
| private int _myVariable;
| int myVariable() {return _myVariable;}
|
| i hope walter considers this, because it would save time

What about other the protection attributes? The meaning of a
"readonly" attribute overlaps with the protection attribute.
What does something like

 readonly public int myVariable;

declare? Or, similarly, what about

 readonly private int myVariable;

Any attribute that controls read/write access needs to spell out
how it interacts with the protection attributes. Perhaps some
fancy protection attribute syntax would be better than a separate
attribute - not that I can think of any good suggestions.

-Ben


Feb 15 2004
prev sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
imr1984 wrote:

[...]
   readonly int myVariable;
 instead of:
   private int _myVariable;
   int myVariable() {return _myVariable;}
 i hope walter considers this, because it would save time

You like creating isles? What do you mean: public int myVariable() ... or protected int myVariable() ... And how to express: protected int _myVariable public int myVariable() ... Three new keywords for some syntactical sugar? If you want to save time while typing, then use a macro editor, that can transform your readonly keyword to the code you desire. I do not like your proposal. So long.
Feb 15 2004