[J3] Why is += missing?

Bader, Reinhold Reinhold.Bader at lrz.de
Wed Aug 25 18:22:43 UTC 2021


Hi Ondrej, 

"+.=" would be sufficiently near to  the C notation as to suggest what it means. 

I don't have specific examples in mind. 
Note though that /= can appear in expressions like

A = B /= C

(A logical, B, C of a type that permits /=). If such appear in statement groups that also use the new operators, 
this would be visually a bit hard on the programmer (not the compiler). 

Cheers
Reinhold

-----Ursprüngliche Nachricht-----
Von: J3 <j3-bounces at mailman.j3-fortran.org> Im Auftrag von Ondrej Certík via J3
Gesendet: Mittwoch, 25. August 2021 19:59
An: J3 Mailinglist <j3 at mailman.j3-fortran.org>
Cc: Ondřej Čertík <ondrej at certik.us>
Betreff: Re: [J3] Why is += missing?



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