On Sunday, 19 August 2018 at 18:32:17 UTC, QueenSvetlana wrote:
In the D Style Guide, it says:

Properties
https://dlang.org/dstyle.html#properties

Functions should be property functions whenever appropriate. In particular, getters and setters should generally be avoided in favor of property functions. And in general, whereas functions should be verbs, properties should be nouns, just like if they were member variables. Getter properties should not alter state.

In the Properties function section, it says:

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

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.

So which is it?

The `@property` annotation might not remain in the language. However, the property call syntax for functions will remain.

So you can write:

---
struct Random
{
  private int value;
  int next() { value++; return value; }
  void seed(int value) { this.value = value; }
}

Random r;
r.seed = 21;
writeln(r.next);
---

That's going to work forever.

You *could* add @property to the next and seed functions. That forces people to use them as fields. However, there's some discussion about how that's going to be handled in the future. So you might want to leave it off.

Reply via email to