[J3] Why is += missing?
Ondřej Čertík
ondrej at certik.us
Wed Aug 25 17:58:33 UTC 2021
On Wed, Aug 25, 2021, at 8:29 AM, Bader, Reinhold via J3 wrote:
[...]
> Wrt /= it is not only the semantic overlap that is an issue but also
> the cognitive load on the programmer (prospective newby: “why the damn
> has /= a different meaning than +=?”)
This is the strongest argument I've seen against adding +=.
Quite frankly, until people pointed that /= is already used in "if (a /= 5) ...", it didn't even crossed my mind to confuse the two. But now when I am aware of it, I don't know. I am not a fan of new operators like "+.=", as it is even more confusing to me what it does. "+=" seems clear from other languages.
I think the best way forward is to simply implement this in a compiler and get some experience using it and see if it is confusing.
So I have implemented it in a compiler as a prototype:
https://gitlab.com/lfortran/lfortran/-/merge_requests/1286
It took me about 40 minutes. I am sure there are many bugs, but += now works for integer, real, scalar and arrays on the left.
Reinhold, do you have some particular code that you think people might find confusing? If you could share it, I can try to compile it and we can play with it.
Ondrej
More information about the J3
mailing list