You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Fortran standard has never mandated short-circuit evaluation of logical operators from the early versions of the language.
This sometimes forces application developers to use nested if statements (e.g. when the second test depends on the outcome of the first one) where it can be done more succintly (and in a more readable form) with languages designed with short-circuit evaluation.
It is of course not possible to change the default behaviour of the language, and sometimes it is desirable NOT to perform short-circuit evaluation. In some cases, the compiler may perform some clever optimizations by changing the order of evaluation, and there is no doubt that some well established Fortran libraries leverage this feature.
But most of the time, for new developments and not backwards compatibility, short circuit evaluation leads to more straightforward and readable statements in my opinion (and eases migration of algorithms from other languages). Of course, one can rely in some cases on compiler's flags to force this behaviour, but that is non portable and bug-prone.
Besides, many newcomers (and even old-timers!) in Fortran are not aware of this feature and assume erroneously that short-circuit applies in Fortran like in other languages they have learned first. This can lead to very difficult bugs to fix.
I have been practising Fortran programming professionnally for 20 years now (along with other langages including C++, Java, Python, etc) and I see no reason for not providing a standard construct to force a snippet of code to perform short circuit evaluation at the user's explicit demand (in the spirit of "implicit none").
Best regards
The text was updated successfully, but these errors were encountered:
@fabrice-ducos thanks for bringing this up. Go ahead and submit any comments or feedback to #19 then. If you have any other comments or proposals, please do not hesitate to open new issues.
The Fortran standard has never mandated short-circuit evaluation of logical operators from the early versions of the language.
This sometimes forces application developers to use nested if statements (e.g. when the second test depends on the outcome of the first one) where it can be done more succintly (and in a more readable form) with languages designed with short-circuit evaluation.
It is of course not possible to change the default behaviour of the language, and sometimes it is desirable NOT to perform short-circuit evaluation. In some cases, the compiler may perform some clever optimizations by changing the order of evaluation, and there is no doubt that some well established Fortran libraries leverage this feature.
But most of the time, for new developments and not backwards compatibility, short circuit evaluation leads to more straightforward and readable statements in my opinion (and eases migration of algorithms from other languages). Of course, one can rely in some cases on compiler's flags to force this behaviour, but that is non portable and bug-prone.
Besides, many newcomers (and even old-timers!) in Fortran are not aware of this feature and assume erroneously that short-circuit applies in Fortran like in other languages they have learned first. This can lead to very difficult bugs to fix.
I have been practising Fortran programming professionnally for 20 years now (along with other langages including C++, Java, Python, etc) and I see no reason for not providing a standard construct to force a snippet of code to perform short circuit evaluation at the user's explicit demand (in the spirit of "implicit none").
Best regards
The text was updated successfully, but these errors were encountered: