why properties don't support +=, -= ... operators?
Andrey via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 23 09:13:19 PDT 2017
Hello! I am constantly worried about this flaw, why this bug
still was not resolved:
https://issues.dlang.org/show_bug.cgi?id=8006
e.g. in Kotlin I can write property like this:
> class Example {
> var value: Int = 0
> set(v) {
> field = v
> }
> get() = field
> }
>
> fun main() {
> var e = Example()
> e.value = 10
> e.value += 1
> println(e.value)
And it will work!
In D I can write something like this:
> class Example {
> private int value_; @property {
> void value(in int val) {
> value_ = val;
> }
> int value() {
> return value_;
> }
> }
> }
That's great, but еhe absence of in-place operators creates
additional problems sometimes, and using ref I think not a good
idea, because of inconsistency.
More information about the Digitalmars-d
mailing list