Jump to page: 1 2
Thread overview
What is the current stage of @property ?
Jun 10, 2020
Vinod K Chandran
Jun 10, 2020
Paul Backus
Jun 10, 2020
12345swordy
Jun 10, 2020
Vinod K Chandran
Jun 10, 2020
12345swordy
Jun 10, 2020
Vinod K Chandran
Jun 10, 2020
H. S. Teoh
Jun 10, 2020
Vinod K Chandran
Jun 10, 2020
Paul Backus
Jun 10, 2020
H. S. Teoh
Jun 10, 2020
Adam D. Ruppe
Jun 10, 2020
Paul Backus
Jun 10, 2020
Paul Backus
Jun 11, 2020
Jonathan M Davis
Jun 11, 2020
H. S. Teoh
Jun 11, 2020
Paul Backus
Jun 12, 2020
H. S. Teoh
June 10, 2020
Hi all,
I read in an old thread that authors of D wants to eliminate @property. I just roughly read the big thread bu couldn't find a conclusion. After all that thread is a 48 page longer jumbo thread. So out of curiosity, i am asking this. What is the current state of @property ? Is it deprecated ?
June 10, 2020
On Wednesday, 10 June 2020 at 20:24:19 UTC, Vinod K Chandran wrote:
> Hi all,
> I read in an old thread that authors of D wants to eliminate @property. I just roughly read the big thread bu couldn't find a conclusion. After all that thread is a 48 page longer jumbo thread. So out of curiosity, i am asking this. What is the current state of @property ? Is it deprecated ?

The current state of @property is that it doesn't really do anything. D allows you to call functions without parentheses, and to use assignment syntax to call a single-argument function, so you can write getters and setters that work like properties even if you don't use the @property annotation:


struct Example
{
    private int x_;
    int x() { return x; } // getter
    void x(int n) { x = n; } // setter
}

void main()
{
    Example e;
    e.x = 123; // calls setter
    int y = e.x; // calls getter
}
June 10, 2020
On Wed, Jun 10, 2020 at 08:24:19PM +0000, Vinod K Chandran via Digitalmars-d-learn wrote:
> Hi all,
> I read in an old thread that authors of D wants to eliminate
> @property. I just roughly read the big thread bu couldn't find a
> conclusion. After all that thread is a 48 page longer jumbo thread. So
> out of curiosity, i am asking this. What is the current state of
> @property ? Is it deprecated ?

It's stuck in limbo, like many things that people just cannot agree on. There are a few places where it's needed (like satisfying the range API, which implicitly checks for it), but for the most part, you can just ignore it, it doesn't really make a big difference.  Life goes on.


T

-- 
English has the lovely word "defenestrate", meaning "to execute by throwing someone out a window", or more recently "to remove Windows from a computer and replace it with something useful". :-) -- John Cowan
June 10, 2020
On Wednesday, 10 June 2020 at 21:40:44 UTC, Paul Backus wrote:
> On Wednesday, 10 June 2020 at 20:24:19 UTC, Vinod K Chandran wrote:
>> Hi all,
>> I read in an old thread that authors of D wants to eliminate @property. I just roughly read the big thread bu couldn't find a conclusion. After all that thread is a 48 page longer jumbo thread. So out of curiosity, i am asking this. What is the current state of @property ? Is it deprecated ?
>
> The current state of @property is that it doesn't really do anything. D allows you to call functions without parentheses, and to use assignment syntax to call a single-argument function, so you can write getters and setters that work like properties even if you don't use the @property annotation:
>
>
> struct Example
> {
>     private int x_;
>     int x() { return x; } // getter
>     void x(int n) { x = n; } // setter
> }
>
> void main()
> {
>     Example e;
>     e.x = 123; // calls setter
>     int y = e.x; // calls getter
> }
It can't do binary operations and unary operations.

June 10, 2020
On Wednesday, 10 June 2020 at 21:40:44 UTC, Paul Backus wrote:

>
> The current state of @property is that it doesn't really do anything. D allows you to call functions without parentheses, and to use assignment syntax to call a single-argument function, so you can write getters and setters that work like properties even if you don't use the @property annotation:
>
>
> struct Example
> {
>     private int x_;
>     int x() { return x; } // getter
>     void x(int n) { x = n; } // setter
> }
>
> void main()
> {
>     Example e;
>     e.x = 123; // calls setter
>     int y = e.x; // calls getter
> }
@Paul Backus, Thanks for the explanation & code sample.

June 10, 2020
On Wednesday, 10 June 2020 at 21:41:54 UTC, H. S. Teoh wrote:

>
> It's stuck in limbo, like many things that people just cannot agree on. There are a few places where it's needed (like satisfying the range API, which implicitly checks for it), but for the most part, you can just ignore it, it doesn't really make a big difference.  Life goes on.
>
>
> T

@H. S. Teoh, Yeah, got it.
June 10, 2020
On Wednesday, 10 June 2020 at 22:15:25 UTC, 12345swordy wrote:

> It can't do binary operations and unary operations.

@12345swordy, You mean we can't do such ops inside the property ?
June 10, 2020
On Wednesday, 10 June 2020 at 21:41:54 UTC, H. S. Teoh wrote:
> There are a few places where it's needed (like satisfying the range API, which implicitly checks for it)

That may have been true at one point, but it isn't true now:

struct S {
    bool empty() { return false; }
    int front() { return 0; }
    void popFront() {}
}

static assert(isInputRange!S); // passes
June 10, 2020
On Wednesday, 10 June 2020 at 22:30:37 UTC, Vinod K Chandran wrote:
> On Wednesday, 10 June 2020 at 22:15:25 UTC, 12345swordy wrote:
>
>> It can't do binary operations and unary operations.
>
> @12345swordy, You mean we can't do such ops inside the property ?

No, it means you can't do this:
e.x += 123;
June 10, 2020
On Wed, Jun 10, 2020 at 10:50:17PM +0000, Paul Backus via Digitalmars-d-learn wrote:
> On Wednesday, 10 June 2020 at 21:41:54 UTC, H. S. Teoh wrote:
> > There are a few places where it's needed (like satisfying the range API, which implicitly checks for it)
> 
> That may have been true at one point, but it isn't true now:
> 
> struct S {
>     bool empty() { return false; }
>     int front() { return 0; }
>     void popFront() {}
> }
> 
> static assert(isInputRange!S); // passes

Nice.  So pretty soon I can get rid of @property spam from my code, which is really not very useful and only adds extra keystrokes for little benefit.


T

-- 
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
« First   ‹ Prev
1 2