www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - CTFE can't replace properties

reply 12345swordy <alexanderheistermann gmail.com> writes:
Reason being that it doesn't support binary operators nor unary 
operators, by using the two functions. It a bad idea to allow 
ctfe to implement them implicitly as that could lead to 
unintentional design by the programmer.


It would be better to implement properties properly and to 
deprecate the  properties attribute.

-Alex
Oct 08 2020
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Oct 08, 2020 at 03:21:57PM +0000, 12345swordy via Digitalmars-d wrote:
 Reason being that it doesn't support binary operators nor unary
 operators, by using the two functions. It a bad idea to allow ctfe to
 implement them implicitly as that could lead to unintentional design
 by the programmer.
 
 It would be better to implement properties properly and to deprecate
 the  properties attribute.
[...] I'm having a hard time understanding what you're trying to say. Could you post some code that illustrates the problem? T -- He who does not appreciate the beauty of language is not worthy to bemoan its flaws.
Oct 08 2020
parent reply 12345swordy <alexanderheistermann gmail.com> writes:
On Thursday, 8 October 2020 at 16:11:02 UTC, H. S. Teoh wrote:
 On Thu, Oct 08, 2020 at 03:21:57PM +0000, 12345swordy via 
 Digitalmars-d wrote:
 Reason being that it doesn't support binary operators nor 
 unary operators, by using the two functions. It a bad idea to 
 allow ctfe to implement them implicitly as that could lead to 
 unintentional design by the programmer.
 
 It would be better to implement properties properly and to 
 deprecate the  properties attribute.
[...] I'm having a hard time understanding what you're trying to say. Could you post some code that illustrates the problem? T
int _x; public int x () { return _x; } int x (int x) { this._x = x; } x += 2; // you can't do this. x++ //nor this.
Oct 08 2020
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Oct 08, 2020 at 04:47:07PM +0000, 12345swordy via Digitalmars-d wrote:
 On Thursday, 8 October 2020 at 16:11:02 UTC, H. S. Teoh wrote:
 On Thu, Oct 08, 2020 at 03:21:57PM +0000, 12345swordy via Digitalmars-d
 wrote:
 Reason being that it doesn't support binary operators nor unary
 operators, by using the two functions. It a bad idea to allow ctfe
 to implement them implicitly as that could lead to unintentional
 design by the programmer.
 
 It would be better to implement properties properly and to
 deprecate the  properties attribute.
[...] I'm having a hard time understanding what you're trying to say. Could you post some code that illustrates the problem?
[...]
 int _x;
 public
 int x () { return _x; }
 int x (int x) { this._x = x; }
 
 x += 2; // you can't do this.
 x++ //nor this.
Operator overloading is only supported by the opXxx member functions. This is by design. But I don't understand what this has to do with CTFE? T -- We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true. -- Robert Wilensk
Oct 08 2020
parent reply 12345swordy <alexanderheistermann gmail.com> writes:
On Thursday, 8 October 2020 at 19:45:15 UTC, H. S. Teoh wrote:
 On Thu, Oct 08, 2020 at 04:47:07PM +0000, 12345swordy via 
 Digitalmars-d wrote:
 On Thursday, 8 October 2020 at 16:11:02 UTC, H. S. Teoh wrote:
 On Thu, Oct 08, 2020 at 03:21:57PM +0000, 12345swordy via 
 Digitalmars-d wrote:
 [...]
[...] I'm having a hard time understanding what you're trying to say. Could you post some code that illustrates the problem?
[...]
 int _x;
 public
 int x () { return _x; }
 int x (int x) { this._x = x; }
 
 x += 2; // you can't do this.
 x++ //nor this.
Operator overloading is only supported by the opXxx member functions. This is by design. But I don't understand what this has to do with CTFE? T
It turns out that it has nothing to do with the CTFE. It simply a limitation that propertiy is supposed to address.
Oct 08 2020
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, Oct 08, 2020 at 07:47:49PM +0000, 12345swordy via Digitalmars-d wrote:
 On Thursday, 8 October 2020 at 19:45:15 UTC, H. S. Teoh wrote:
 On Thu, Oct 08, 2020 at 04:47:07PM +0000, 12345swordy via Digitalmars-d
 wrote:
[...]
 int _x;
 public
 int x () { return _x; }
 int x (int x) { this._x = x; }
 
 x += 2; // you can't do this.
 x++ //nor this.
Operator overloading is only supported by the opXxx member functions. This is by design. But I don't understand what this has to do with CTFE?
[...]
 It turns out that it has nothing to do with the CTFE. It simply a
 limitation that  propertiy is supposed to address.
Ah, now I understand. Yeah, property is poorly-implemented, and generally a mess beyond the most rudimentary of use cases. I usually don't bother with it except where I absolutely have to. Though if you really care about it, filing an enhancement request might be a way of documenting this particular use case, in case we ever revisit this feature again. T -- Guns don't kill people. Bullets do.
Oct 08 2020
parent Ahmet Sait <nightmarex1337 hotmail.com> writes:
https://issues.dlang.org/show_bug.cgi?id=8006

https://issues.dlang.org/show_bug.cgi?id=15231
Oct 09 2020