September 28, 2022

On Monday, 26 September 2022 at 18:51:41 UTC, Ali Çehreli wrote:

>

On 9/26/22 11:50, Dom DiSc wrote:

>

if x is a property
(having a getter and a setter), ++x should work

That came up a couple of times on this thread.

Sounds easy to my ears. Is there a blocker for the implementation?

Ali

A nested struct can  do this, but each field needs a new build. For example to Inner z in code:

template foo(T)
{
  struct Inner
  {
    T bar;
    alias bar this;
    auto opUnary(string op)()
    if(op == "++")
    {
      ++bar;
      return this;
    }
  }
  Inner z;
}

struct Outer(T)
{
  T X, Y;

  mixin foo!T s;
  alias z = s.z;

  auto x() { return X; }
  auto x(T n) { return X = n; }

  auto y() { return Y; }
  auto y(T n) { return Y = n; }
}

import std.stdio;
void main()
{
  auto outer = Outer!int();
  with(outer)
  {
    x = 320;
    y = 240;
    z = 160;
    z++;

    writefln!"x = %s, y = %s, z = %s"
    (x, y, z); // x = 320, y = 240, z = 161
  }
}

SDB@79

September 28, 2022
I'm using @property a lot of places, in the hope that one day it would receive a full set of useful semantics - and also as a way to add a distinction between "verb" functions and simple getters/setters. There are also definitely some places where the current semantics are in effect.

IMO, the possible `writeln = "foo";` syntax, on the other hand, results in rather surprising semantics, and if that wouldn't result in a ton of breakage, I'd rather see that gone.

September 29, 2022

On Wednesday, 28 September 2022 at 18:47:24 UTC, Sönke Ludwig wrote:

>

I'm using @property a lot of places, in the hope that one day it would receive a full set of useful semantics – and also as a way to add a distinction between "verb" functions and simple getters/setters. There are also definitely some places where the current semantics are in effect.

With other words, you’re setting yourself up to have your code broken.

September 29, 2022

On Thursday, 29 September 2022 at 08:40:11 UTC, Quirin Schroll wrote:

>

On Wednesday, 28 September 2022 at 18:47:24 UTC, Sönke Ludwig wrote:

>

I'm using @property a lot of places, in the hope that one day it would receive a full set of useful semantics – and also as a way to add a distinction between "verb" functions and simple getters/setters. There are also definitely some places where the current semantics are in effect.

With other words, you’re setting yourself up to have your code broken.

Well, sort of. But in hope to get something more useful as it is now.

But what a suggestive question! You either don't use @properties so the feature is useless and can be thrown away, or you use them and then be blamed to shoot yourself into your foot.

September 29, 2022

On Thursday, 29 September 2022 at 08:40:11 UTC, Quirin Schroll wrote:

>

On Wednesday, 28 September 2022 at 18:47:24 UTC, Sönke Ludwig wrote:

>

I'm using @property a lot of places, in the hope that one day it would receive a full set of useful semantics – and also as a way to add a distinction between "verb" functions and simple getters/setters. There are also definitely some places where the current semantics are in effect.

With other words, you’re setting yourself up to have your code broken.

No problem for a code gunslinger. Well, we can clean up easily without writing a new parser. 😀

By the way, I use it occasionally.
..

SDB@78

September 30, 2022

On Thursday, 29 September 2022 at 11:53:56 UTC, Dom DiSc wrote:

>

On Thursday, 29 September 2022 at 08:40:11 UTC, Quirin Schroll wrote:

>

On Wednesday, 28 September 2022 at 18:47:24 UTC, Sönke Ludwig wrote:

>

[...]

With other words, you’re setting yourself up to have your code broken.

Well, sort of. But in hope to get something more useful as it is now.

But what a suggestive question! You either don't use @properties so the feature is useless and can be thrown away, or you use them and then be blamed to shoot yourself into your foot.

To be fair, the language spec does recommend not using it

>

WARNING: The definition and usefulness of property functions is being reviewed, and the implementation is currently incomplete. Using property functions is not recommended until the definition is more certain and implementation more mature.

https://dlang.org/spec/function.html#property-functions

September 30, 2022

On Friday, 30 September 2022 at 03:20:31 UTC, Tejas wrote:

>

To be fair, the language spec does recommend not using it

>

WARNING: The definition and usefulness of property functions is being reviewed, and the implementation is currently incomplete. Using property functions is not recommended until the definition is more certain and implementation more mature.

https://dlang.org/spec/function.html#property-functions

Interestingly, Phobos is full of them. For example, if you are using Appender, your path goes through @property. 😀
SDB@79

September 30, 2022
What '@property' gains or should gain over '// property'?


October 01, 2022

On Wednesday, 14 September 2022 at 19:20:04 UTC, Rikki Cattermole wrote:

>

Recently Walter has been wanting to remove language features that don't need to be kept to simplify the language.

It seems everybody agrees that binary literals are not a worthy candidate for removal, but one thing that I kept thinking about was @property. As far as I know, hardly anyone actually uses its semantic behaviors, and the ones that it does have which are incomplete are special cases that don't benefit us all that much.

I was going to post this yesterday, but it turns out I am not alone in thinking this can be removed safely (can be swapped to a UDA to prevent code breakage without any language additions).

So, who uses @property semantics?

https://dlang.org/spec/function.html#property-functions

Can we fix instead?

The current situation is ripped with problems.

October 01, 2022
On Friday, 30 September 2022 at 13:30:31 UTC, razyk wrote:
>
> What '@property' gains or should gain over '// property'?

It gives you control over the access to a member
- you can read it (if there is a getter)
- you can write it (if there is a setter)
- you can apply operations on it that both read and write it (like ++ if there is both a getter and a setter)
- you cannot get its address (use function or variable if you want this)

- property allows you to calculate the requested value instead of storing it somewhere. But you can't get the address of a calculation (what should that be? The address of some temporary storage? A pointer to the stack? A pointer to the function that performs the calculation? But which one? The getter or the setter? None of those makes any sense)