www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - another properties thread

reply Moth <postmaster gmail.com> writes:
hello all. it's been a little while.
last year i found that the D spec concerning  property is in 
limbo, with the [official 
documentation](https://dlang.org/spec/function.html#property-functions)
recommending against its use for almost three years at this point.

this was an upset, but dealable - it was ugly and long-winded, 
but i could work around the limitation by using manual getter and 
setter methods.

however, recently i discovered that the implementation of the 
bitfields template - the use of which is [stated to be a best 
practice by the 
documentation](https://dlang.org/spec/struct.html) - also [uses 
 property](https://github.com/dlang/phobos/blob/master/std/bitmanip.d#L114) in
the code it generates.

this concerns me greatly. surely the standard library should be 
stable, not using half-implemented features that may be removed 
in the future - should i stop using bitfields? i've read 
elsewhere on this forum that the maintainers don't see  property 
as important, but this seems rather critical to me - is there 
likely to be any change in their stance on the issue? i would 
much, *much* rather use  property than not.

i hope i have not caused any offense with this post, but this 
situation really is frustrating, and i wanted to get it off my 
chest.
Apr 21 2021
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Thursday, 22 April 2021 at 02:25:29 UTC, Moth wrote:
 this was an upset, but dealable - it was ugly and long-winded, 
 but i could work around the limitation by using manual getter 
 and setter methods.
The property annotation does almost nothing, so you can still do properties without the annotation. The only thing property actually does is change `typeof(obj.prop)` afrom function over to the type it returns.
 i would much, *much* rather use  property than not.
Why? What exactly do you need it to do? (I myself want property to be fixed but I have a specific list of cases why, so curious what you are thinking of...)
Apr 21 2021
parent reply drug <drug2004 bk.ru> writes:
22.04.2021 05:41, Adam D. Ruppe пишет:
 On Thursday, 22 April 2021 at 02:25:29 UTC, Moth wrote:
 this was an upset, but dealable - it was ugly and long-winded, but i 
 could work around the limitation by using manual getter and setter 
 methods.
The property annotation does almost nothing, so you can still do properties without the annotation. The only thing property actually does is change `typeof(obj.prop)` afrom function over to the type it returns.
 i would much, *much* rather use  property than not.
Why? What exactly do you need it to do? (I myself want property to be fixed but I have a specific list of cases why, so curious what you are thinking of...)
I use property in my gui, it is really handy to be able to draw all public members and properties of some data structure just passing it to widget using reflection. In other case I would be forced to use yet another attribute, but this attribute wouldn't be so handy because property is a part of the language. I do not hesitate to use properties in my code and still have no any problem with them, so why not?
Apr 22 2021
next sibling parent reply Luhrel <lucien.perregaux gmail.com> writes:
On Thursday, 22 April 2021 at 07:44:42 UTC, drug wrote:
 22.04.2021 05:41, Adam D. Ruppe пишет:
 On Thursday, 22 April 2021 at 02:25:29 UTC, Moth wrote:
 [...]
The property annotation does almost nothing, so you can still do properties without the annotation. The only thing property actually does is change `typeof(obj.prop)` afrom function over to the type it returns.
 [...]
Why? What exactly do you need it to do? (I myself want property to be fixed but I have a specific list of cases why, so curious what you are thinking of...)
I use property in my gui, it is really handy to be able to draw all public members and properties of some data structure just passing it to widget using reflection. In other case I would be forced to use yet another attribute, but this attribute wouldn't be so handy because property is a part of the language. I do not hesitate to use properties in my code and still have no any problem with them, so why not?
Some basic functionalities like `prop += 3` / `++prop` are not working. 12345swordy tried to fix that in PR https://github.com/dlang/dmd/pull/12097), but there's no activity since 3 months so idk.
Apr 26 2021
parent 12345swordy <alexanderheistermann gmail.com> writes:
On Monday, 26 April 2021 at 18:14:49 UTC, Luhrel wrote:
 On Thursday, 22 April 2021 at 07:44:42 UTC, drug wrote:
 22.04.2021 05:41, Adam D. Ruppe пишет:
 On Thursday, 22 April 2021 at 02:25:29 UTC, Moth wrote:
 [...]
The property annotation does almost nothing, so you can still do properties without the annotation. The only thing property actually does is change `typeof(obj.prop)` afrom function over to the type it returns.
 [...]
Why? What exactly do you need it to do? (I myself want property to be fixed but I have a specific list of cases why, so curious what you are thinking of...)
I use property in my gui, it is really handy to be able to draw all public members and properties of some data structure just passing it to widget using reflection. In other case I would be forced to use yet another attribute, but this attribute wouldn't be so handy because property is a part of the language. I do not hesitate to use properties in my code and still have no any problem with them, so why not?
Some basic functionalities like `prop += 3` / `++prop` are not working. 12345swordy tried to fix that in PR https://github.com/dlang/dmd/pull/12097), but there's no activity since 3 months so idk.
I am still here. It just that I don't have any time for it. -Alex
Apr 29 2021
prev sibling parent reply Kagamin <spam here.lot> writes:
On Thursday, 22 April 2021 at 07:44:42 UTC, drug wrote:
 I use  property in my gui, it is really handy to be able to 
 draw all public members and properties of some data structure 
 just passing it to widget using reflection.
Why public members are not enough for you?
Apr 28 2021
parent reply drug <drug2004 bk.ru> writes:
28.04.2021 19:39, Kagamin пишет:
 On Thursday, 22 April 2021 at 07:44:42 UTC, drug wrote:
 I use  property in my gui, it is really handy to be able to draw all 
 public members and properties of some data structure just passing it 
 to widget using reflection.
Why public members are not enough for you?
I need to visualize my data like debuggers do. I need only state (i.e. fields) and don't need methods. And property let me mark methods that should be considered as fields. But it turns out that in non trivial cases I need additional UDAs to control visualization anyway so I can use another UDA instead of property.
Apr 28 2021
parent Kagamin <spam here.lot> writes:
On Wednesday, 28 April 2021 at 17:00:34 UTC, drug wrote:
 28.04.2021 19:39, Kagamin пишет:
 On Thursday, 22 April 2021 at 07:44:42 UTC, drug wrote:
 I use  property in my gui, it is really handy to be able to 
 draw all public members and properties of some data structure 
 just passing it to widget using reflection.
Why public members are not enough for you?
I need to visualize my data like debuggers do. I need only state (i.e. fields) and don't need methods. And property let me mark methods that should be considered as fields. But it turns out that in non trivial cases I need additional UDAs to control visualization anyway so I can use another UDA instead of property.
You can do it like this: int property(T)(T); //for introspection struct A { int a(int); int b(); int c; } A a; static if(is(typeof(property(a.b)))) {...}
Apr 29 2021