Chris Angelico wrote:
On Thu, Aug 28, 2014 at 4:09 PM, Stephen R. van den Berg srb@cuci.nl wrote:
The operation could be determined by "overloading" based on types. I.e. a String Buffer `=(string a) would only activate when the lvalue is a buffer type, and the rvalue is of type string.
Maybe. Still strikes me as dangerously magical. I'd much rather mutation be done with methods (or augmented assignments).
As with all lfun-magic, it should be applied within reason, and thus should only be used if the result is intuitive to the reader. The whole point of lfuns is that people expect operators to behave in certain ways, so it is shorthand for named methods. Likewise in this case.
In case of a String.Buffer, if I have:
String.Buffer b="abcdef"; b+="ghi"; write(b); b="jkl"; b+="mno"; write(b);
Then it strikes me as "obvious" that this would result in printing abcdefghi and jklmno.