https://dpaste.dzfl.pl/6c6e614b58ac

The problem given in the list, is that a ref getter is used when a setter does not exist. Why have a setter then?

One problem is that if the setter has different behavior than the getter there will be problems.

The other problem is that += modifies the value.

normally getters are thought to be immutable in the since that they just return a value.

but

a += will modify what a points to.

Using setters, we might want to trigger an event when the value changes. But since the getter is used and can modify the event won't be triggered.

This is a bad design.

any modifying operator should call the setter. This is precisely what "set mean".


a += b is suppose to be syntactic sugar for a = a + b, yet we get different behavior. In one case only a getter is called and in the second case the getter and then the setter.

How D currently handles this is wrong and error prone. Either depreciate the use of op assignments using properties or fix it! lvalues should ALWAYS use the setter, it makes no sense otherwise.



Reply via email to