[J3] Why is += missing?
Malcolm Cohen
malcolm at nag-j.co.jp
Thu Aug 26 02:47:31 UTC 2021
Well, I don’t like it.
Below are some reasons and comments. Perhaps not overly compelling, but they are, I think, quite valid reasons for not doing this.
A: It bloats the language with extra (and un-Fortran-like) syntax. There is a cognitive load associated with the size of a language.
B: Then there’s the “why not operator= for all operators”. Doing that would change it from a smallish feature into a largish feature (quite apart from the ambiguity with /=). Not doing that would result in C-familiar user annoyance when the “obvious” things did not work.
C: It is not self-explanatory at all; many Fortran users are not familiar with C or C++.
D: As noted by someone else, it is not the same as X = X + expr, because the compiler can evaluate any mathematical equivalent to “X+expr”, and that is lost with the “obvious” semantics of “add expr to X”. With FMA and similar being quite popular these days, I’d expect some but not all compilers would violate those semantics at least some of the time by turning it back into X=X+expr (to avoid losing performance and accuracy). That’s a recipe for reduced portability.
E: The density of “+=” and friends in C code is not necessarily a good indication of how widely used it would be in Fortran. Quite apart from some uses of += being trivial (N=N+2 is certainly not less readable than N+=2), and some already being handled by ASSOCIATE as previously mentioned, some cases might be covered by a totally different Fortran feature, for example the SUM intrinsic.
F: For that matter, “++” is likely widely used in C codes. That does not mean it would be a good fit for Fortran.
For me, “B” by itself is sufficient to make this not worthwhile.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Damian Rouson via J3
Sent: Thursday, August 26, 2021 8:47 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Damian Rouson <damian at sourceryinstitute.org>
Subject: Re: [J3] Why is += missing?
On Wed, Aug 25, 2021 at 6:27 AM Jeff Hammond via J3 <j3 at mailman.j3-fortran.org <mailto:j3 at mailman.j3-fortran.org> > wrote:
I will argue that it is syntactic sugar in the same sense that multidimensional arrays are. Below is the perfectly functional C code I wrote to match my Fortran years ago (because computer scientists don’t know their history). There is no actual need for multidimensional arrays in Fortran, just the practical difficulty of not having them.
// t3(h3,h2,h1,p6,p5,p4)+=t1(p4,h1)*v2(h3,h2,p6,p5);
t3[h3+h3u*(h2+h2u*(h1+h1u*(p6+p6u*(p5+p5u*p4))))] += t1[p4+p4u*h1] * v2[h3+h3u*(h2+h2u*(p6+p6u*p5))];
Jeff,
If I'm interpreting the responses accurately, it sounds like the idea simply fell too far down the list of priorities, but I haven't heard any fundamental resistance modulo syntax. Hopefully that's encouraging.
Is the provided C code really so short or were the nested for loops omitted for the sake of brevity?
Damian
Disclaimer
The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: 30 St. Giles, Oxford, OX1 3LE, United Kingdom. Please see our Privacy Notice <https://www.nag.co.uk/content/privacy-notice> for information on how we process personal data and for details of how to stop or limit communications from us.
This e-mail has been scanned for all viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210826/c6107c4b/attachment.htm>
More information about the J3
mailing list