www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - property

reply Fyodor Ustinov <ufm ufm.su> writes:
Hi!

Why do need " proprety" if everything works without it?

WBR,
     Fyodor.
Nov 09 2015
next sibling parent reply Alex Parrill <initrd.gz gmail.com> writes:
On Monday, 9 November 2015 at 21:56:22 UTC, Fyodor Ustinov wrote:
 Hi!

 Why do need " proprety" if everything works without it?

 WBR,
     Fyodor.
Check out the following code: struct Test { int foo() { return 2; } int bar() property { return 2; } } pragma(msg, typeof(Test.foo)); // Prints int(); i.e. a zero-argument function that returns an int pragma(msg, typeof(Test.bar)); // Prints int; i.e. a plain int AFAIK when property was introduced, it was expected that after a deprecation period, calling non-property functions without parenthesis would be invalid, but I don't think that panned out. It's still good for documentation.
Nov 09 2015
parent reply Fyodor Ustinov <ufm ufm.su> writes:
On Monday, 9 November 2015 at 22:06:22 UTC, Alex Parrill wrote:
 Check out the following code:


 	struct Test {
 		int foo() {
 			return 2;
 		}
 		int bar()  property {
 			return 2;
 		}
 	}

 	pragma(msg, typeof(Test.foo)); // Prints int(); i.e. a 
 zero-argument function that returns an int
 	pragma(msg, typeof(Test.bar)); // Prints int; i.e. a plain int
But the compiler is lying! void main() { auto a = Test(); auto aa = &a.bar; // if type of a.bar is int writeln(*aa); // why: Error: can only * a pointer, not a 'int delegate() property' }
 AFAIK when  property was introduced, it was expected that after 
 a deprecation period, calling non-property functions without 
 parenthesis would be invalid, but I don't think that panned 
 out. It's still good for documentation.
If this feature will be removed, it will be very lacking code, like: writeln = "Hello, world!"; :) WBR, Fyodor.
Nov 09 2015
parent reply Gary Willoughby <dev nomad.so> writes:
On Monday, 9 November 2015 at 22:42:16 UTC, Fyodor Ustinov wrote:
 If this feature will be removed, it will be very lacking code, 
 like:

 writeln = "Hello, world!";

 :)
 WBR,
     Fyodor.
The feature is not being removed. Only the property attribute and compiler check is being removed.
Nov 10 2015
parent Jonathan M Davis via Digitalmars-d-learn writes:
On Tuesday, November 10, 2015 09:53:42 Gary Willoughby via Digitalmars-d-learn
wrote:
 On Monday, 9 November 2015 at 22:42:16 UTC, Fyodor Ustinov wrote:
 If this feature will be removed, it will be very lacking code,
 like:

 writeln = "Hello, world!";

 :)
 WBR,
     Fyodor.
The feature is not being removed. Only the property attribute and compiler check is being removed.
All that's being removed at this point is the -property switch which enforced that non- property functions be called with parens (since once UFCS was introduced, everyone hated having to provide empty parens for function calls that already had parens for template arguments). It's still up for discussion what we're going to do in terms of enforcing that property functions get called without parens or whether we're going to require property for the setter syntax, though we almost have to make it so that if an property function returns a callable (e.g. delegate) that the parens call that callable, otherwise you really can't have property functions that return callables. For now, property is _mostly_ for documentation purposes (though it does affect a few things like typeof). There are multiple DIPs on the topic (e.g. http://wiki.dlang.org/DIP23 ), but until one is accepted, we don't know for sure what's going to happen with property. - Jonathan M Davis
Nov 10 2015
prev sibling parent Kagamin <spam here.lot> writes:
It was intended for stricter properties. See 
http://dlang.org/changelog/2.069.0.html#property-switch-deprecated Last
iteration on it was http://wiki.dlang.org/DIP23
Nov 10 2015