Skip to content

Allow short-circuit evaluation of operators on explicit user's demand #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fabrice-ducos opened this issue May 20, 2021 · 4 comments
Closed

Comments

@fabrice-ducos
Copy link

fabrice-ducos commented May 20, 2021

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

@certik
Copy link
Member

certik commented May 20, 2021

Related: #19.

@fabrice-ducos
Copy link
Author

Thank you for your reply. Indeed, this topic has already been addressed.
I will therefore close this issue.

@certik
Copy link
Member

certik commented May 20, 2021

@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.

@fabrice-ducos
Copy link
Author

fabrice-ducos commented May 20, 2021

Thank you dear @certik . Don't hesitate to add a link to my remarks #206 at #19 if you wish to revive the topic.

From the discussion, I understand that a proposal is already on the worklist of the committee.

EDIT: you already did ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants