www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: seeding the pot for 2.0 features

reply doob <doobnet gmail.com> writes:
Chad J Wrote:

 BCS wrote:
 Now that the big 1.0 is out, I think that we should start considering 
 what to put into 2.0. I don't think we need to rush anything into D yet, 
 but maybe we should start accumulating a list of things to consider.
 
 One overall thought I had is that it seems the big killer for C++ was to 
 some extent that it is a strict superset of C. Maybe we should avoid 
 this problem and not requiter that D2.0 be backwards compatible at the 
 source level, but only at the ABI level sort of like C and D are now. 
 Anyway, just a thought.

... The first thing that comes to my mind is explicit properties. I believe they can be done without using new keywords or sacrificing much generality. Eventually the implicit properties could be deprecated, when everyone feels they are no longer widely used.

I think it would be good to add a "property" keyword and maybe also "get" and "set". I think also would be nice to add a feature from ruby that i think works something like this: Ruby code: class C { attr_reader :variable1, :variable2, :variable3 } and this will create a private variable and a read property. And ther is also "attr_writer" to create a write property. In D this could look something like this D code: class C { property { int variable1; char[] variable2; int variable3; } } This would create a private variable and a get and set property method. Then you could also write like this: D code: class C { private property { int variable1; char[] variable2; int variable3; } } to make the get and set property methods private. You could write like this: D code: class C { get { int variable1; char[] variable2; int variable3; } } to only make a private variable and a get property method. The get and set methods would be public as default(i think) and the variable would always be private. I think it would be great if you could write as i have described above because when you want a private variable and get and set methods that only sets or returns the value. If you would like to do something in the methods it could look like this: D code: class C { private int variable_; public get int variable () { return variable_; } public set int variable (int variable) { if (variable > 3) return variable_ = variable; } }
Feb 05 2007
parent BCS <ao pathlink.com> writes:
Reply to doob,

 I think it would be good to add a "property" keyword and maybe also
 "get" and "set". I think also would be nice to add a feature from ruby
 that i think works something like this:
 

befor I'd go for that it rather see const aliases class C { private int foo; const alias Foo; } C c = new c; auto cf = c.Foo; // valid c.Foo = 2; // invalid auto cf = &c.Foo; // invlaid That covers the get side, and what use is the set side if you don't provide code? (Overriding maybe??) I /like/ the property syntax D uses and would hate to see it discarded.
Feb 05 2007