-
Notifications
You must be signed in to change notification settings - Fork 17
An alternate take on Enumeration Types: an approach seeking to help Fortranners avoid "magic" values in code #46
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
Comments
@FortranFan Thanks a lot for opening a discussion regarding this. I was on the Data subcommittee where your paper got discussed --- if I remember well, we went over your paper and tried to extract useful things that were not part of the other proposal in #11. The issue was that there was apparently already an effort from Tokyo, as documented in #11, and your effort was not coordinated with them. Had we used github already, we would know about these efforts and could coordinate better. By looking at the use cases and motivation at #11, I am not convinced that they have done due diligence to explore how other languages do that, nor many examples how enumeration is actually used in codes. Either way, let's start over, and discuss the use cases, then try to formulate what features the community would like and then try to create a solid proposal for the next meeting. I see several issues that the committee was trying to figure out, and we need to have good arguments why yes, or why not:
Are there other questions that we do not have agreement on? I would start thoroughly discussing these and find an agreement on these questions first, or at least list pros and cons. I noticed suggestions at the J3 mailinglist for not doing any work on this until our next meeting, when somehow it will be time for action. I think we should do the opposite -- we should try to do as much work as we can remotely, so that when we meet the next time, we either have a solid proposal, or solid lists of pros and cons, and we can vote what we want to do. |
I agree that the committee needs to do a more extensive review of how enumerators are used in other languages and even more thought on how they would be used in Fortran codes. Given Fortrans traditional focus on scientific and engineering programming, some of the use cases in other languages might not be appropriate. I currently use them extensively as a convienient way of defining parameters for SELECT CASE selectors since I find that easier than creating individual INTEGER, PARAMETER values for each one. Most of the time you care less about what the actual value is than is it different from other values. As a first step to defining a full enumerator cabability I would do the following.
This addresses what I consider the first and most important (for me at least) of use case for enumerators. Ie as a more convienient way of defining parameters without resorting to individual PARAMETER statements for each value |
@rweed wrote:
Re: other languages and what is appropriate or not, consider J3 Fortran paper 19-216r1 discussed at the Tokyo meeting which was the basis for crucial decision(s) by the WG5 body, decision(s) that might constrain and limit what will get introduced to Fortran 202X. That paper mentions 4 other programming languages in its Introduction starting with C; it also states, "Pascal, Modula-2, Ada, ... have proper enumeration types, and enumerators of those types, because they are useful." and elsewhere in WG5/J3 documents it has been mentioned Fortran 202X shall have "proper enumeration types". Now, note in connection with Ada being mentioned in 19-216r1: one of the features under consideration toward enumeration types in Fortran is %NEXT ( or ..%NEXT()) ) and %PREV ( or ..%PREV() ) to loop over enumerators in a type instance. This has similarities with facilities in Ada such as 'SUCC and 'PRED in Ada: see here. Few other languages support such as a facility with their enumeration types. I then ask:
|
@certik wrote:
Thank you @certik , your proposed path forward makes perfect sense. Issue threads such as this and the comments therein can hopefully provide the background material for all interested Fortranners to provide better input and develop better proposals and make better decisions. |
@FortranFan I agree with you that the justification based on Ada is not consistent with the idea to look at all modern highly used languages (I like your IEEE list) and see what they do and then choose what's best for Fortran. It seems that Ada is cherry-picked, and even that inconsistently, as you pointed out. Note that Ada seems to have In case of Fortran, we do not have So given that, the "natural" position is not to have In a similar way, I would like to tackle all the other questions. |
@certik and all interested in Enumerations in Fortran, please take a look at this PEP for Python. With paper 19-229 mentioned above, my hope was to provide the background and use cases that would help the Fortran committee develop a comprehensive facility that is consistent with the legacy, semantics, and syntax of Fortran, similar to what one notices the Python org did with their PEP 435 back in year 2013. If one looks at Python PEP, one can effectively feel the care and concern and the motivation to really help the practitioners of Python do better with their code. And consider the basic aspect of enum type in Python with the ability of assign value to an enumeration member (aka enumerator per current papers on Fortran): >>> from enum import Enum
>>> class Color(Enum):
... red = 1
... green = 2
... blue = 3 This is something you will notice with almost all the languages seeing any significant use in numerical computing, whether it be Ada (embedded and real-time systems e.g., avionics and aerospace applications), C++, C#, Java, etc. What is on the horizon for Fortran plans to deny this basic ability to assign any values in Fortran enumerations (they can only be auto-assigned starting with unity in the order of enumerators) which, right off the bat, invalidates so many use cases based on existing codebases toward engineering and technical computing I have seen. For a language like Fortran which essentially disallows any named constants or variables to come into existence with an automatic value (without negative consequences), it appears entirely orthogonal to existing semantics what is being considered with the current plan for enumeration type. This is highly bothersome to me. |
I submitted this paper 19-229 at the recent J3 meeting in Las Vegas (October 14 - 18, 2019) but it was ignored on account of being inconsistent with the decision(s) at the joint WG5/J3 meeting in Tokyo earlier in August. I was motivated to submit 19-229 based on the needs, use cases, and requirements (as explained below) I foresee users will want in Fortran towards their applications in scientific and technical computing and which were either not tabled during the discussion at Tokyo or they were addressed rather inadequately.
Take the IEEE spectrum rankings for most popular languages now and review the facilities toward enumerations in any of the top ones e.g., Swift as described here. Should Fortranners want to start expressing their coding constructs in Fortran as clearly and succinctly as possible using any of these other options available to engineers and scientists and where type-safety is to be valued and "magic" values are to be avoided (I'll provide more information toward this later on in the comments section), they will seek a comprehensive facility similar to what is offered by, say, Swift language. However what is on the anvil for Fortran 202X is a poor shadow of this, so the situation is of great concern to me.
From the paper:
Introduction
This paper, while trying to build upon the benefits and features of enumeration types known generally and also stated in the above referenced papers, attempts to document the use-cases and example code snippets derived from extensive use of enumeration types with other programming languages that are currently used indescribably more widely than Fortran in chemical processing and manufacturing industry even in engineering and scientific technical/numerical domains and applications. "No magic numbers in code" and type-safe programming are among the most basic aspects of the good coding practices (GCP) sought after by managers and technical leads toward computing in such industry. But even in these aspects, Fortran falls short relative to other top programming languages today and this gap compounds the reasons why Fortran does not get considered for any large and/or new application developments. It is therefore critically important the facility toward enumeration types in Fortran be developed comprehensively to support a wide spectrum of beneficial use cases in scientific and technical programming. The section below strives to list all the cases from industrial experience and to extract feature requirements from these examples so that the formal specifications toward this facility can be pursued.
The text was updated successfully, but these errors were encountered: