Code standards #551
Replies: 16 comments 34 replies
-
I think it's good to have a set of standards for WW3, and I like all the ones so far proposed. I had one comment on the spacing/alignment. I have a slight preference towards 4 spaces for clarity, though would be fine with 2 otherwise. |
Beta Was this translation helpful? Give feedback.
-
Tagging @UKMO-lsampson as he may have some recommendations regarding code standards off the back of the OpenACC work he has been doing. |
Beta Was this translation helpful? Give feedback.
-
Do we want to set a line length limit? |
Beta Was this translation helpful? Give feedback.
-
As part of the work @mvertens and I have been doing regarding ifdef removal (discussion #763), we've created this list of best practices for discussion. Best coding practices
Indent/Comment structureThe python script developed by @mvertens to automatically replace #ifdefs with logical flags also implements standard fortran90 indent and comment structure via emacs. This function allows f90 program control to be indented and commented in a uniform manner. This produces standard F90 indenting and commenting as
|
Beta Was this translation helpful? Give feedback.
-
While I agree about the need to have better standards of writing,
Some rules like "good comments" are very good but it should be precise. I would propose:
Further thoughts:
|
Beta Was this translation helpful? Give feedback.
-
Hi everybody, i start small but I will expand slowly ... 72 line length does not follow the F90 standard which is 132. Moreover this makes the code lengthy, hard to read and is something from the time when we had this https://de.wikipedia.org/wiki/Lochkarte. I do not understand the motivation for this. Rather I would write a python script to get rid of it. I think we do not want to go back to the year '77. I would like to understand the motivation having 72 line length. What is the reasoning for this, what is the benefit? Cheers Aron |
Beta Was this translation helpful? Give feedback.
-
Hello everybody, when I was a decade ago at ECMWF i had the opportunity to talk to a young smart guy from the computational science division. It was exactly about the same topic and I have reported that during my visit in Washington approx. 5 years ago. Basically, it would be a bit different than what was suggested here and I like to move now to the "use only" topic. Especially, if #ifdef is contained in the "use only" part. Now let me explain what I have picked and what I agree with. Now making extensive usage of "use" statements outside of the "driver" subroutines is not a good way to proceed. The reasons are the following:
I conclusion the usage of "use only" is not something that is very helpful, neither it is good for optimization or allows easy going code development, rather we should have "implicit none" without "use only" + "intent" statement in the subroutine header, which renders the various subroutines self contained. Now we have opened here clearly a Pandora box, which is great but WW3 is now in a state of very rapid development and certain changes go from top to bottom. I am afraid that this will increase significantly the work load for all involved persons. Which is clearly worthwhile but which is maybe not now the time to go. My suggestion is that we further discuss and negotiate and do it slowly part by part. If something is really a hard problem for certain development we should seek & destroy but otherwise we should wisely design and coordinate. I am opposed of such top level code changes that are not touching the essence of the problem and I think that we need to work now problem oriented rather than making large global changes that directly affect all ongoing developments and resulting in significant code changes. I will comment more on the other points but all of them need a lot of attention a lot of thinking in the future as well as adjustment with the ongoing work. Nevertheless, it is super important to carry that forward and I strongly appreciate the action that have been take here. Maybe a good start would be get rid of the #ifdefs for only the source terms but that would result then of the input files. Otherwise the other coding standards suggested by Jessica are fine with me. Cheers Aron |
Beta Was this translation helpful? Give feedback.
-
Hi All, I like also to add that the PDLIB implementation and also all the DEBUG** code is not consolidated nor fully optimized. The problem is that we have always some problems, milestones, new developments, which hardly leave us time to consolidate and therefore I even more appreciate all this efforts, since this will reduce development time and errors during coding. Maybe we can even agree on a coding marathon all together? Let's see during the user meeting. However, we need to have 1st some decent plan to carry on and define priorities. At least from my point of view. Cheers Aron |
Beta Was this translation helpful? Give feedback.
-
One extra thing I would like to suggest is adding a comment on the This will help with identifying the associated IF statement. I know this should be a lot easier once the indenting is sorted out, but there are still some very large |
Beta Was this translation helpful? Give feedback.
-
slides from Sep 6th Developer call |
Beta Was this translation helpful? Give feedback.
-
Hi Everyone - While this can always be a continual conversation, we are going to be taking into consideration comments made through Sunday, 9/12/22 and then the code managers will be taking into consideration all of the comments here and creating a list of code standard for WW3, which will be posted here 9/14/22. We appreciate your input and feedback and a big thanks to @DeniseWorthen and @mvertens for their presentation and efforts to move this conversation forward! |
Beta Was this translation helpful? Give feedback.
-
Hi there, thank you for the presentations. I do like all of the proposed code changes. Particularly the use only option. Some function read/write directly from data arrays in other modules. Other will pass arrays through subroutines. From memory there should be a comment section in the header explaining if data is read or written. This may have been forgotten to update during code changes. |
Beta Was this translation helpful? Give feedback.
-
I basically agree with the coding standards except some things, which I am opposing.
Otherwise I am more than happy about the outcome of this discussion. Cheers Aron |
Beta Was this translation helpful? Give feedback.
-
Here is a real life example that illustrates the problem. The topics in 4b and 4c build on this. In the best case, the programming error is detected at compile time and thus a faulty program does not arise in the first place. Here is a code snippet from UnRunOff with an error that didn't noticeably change the results. (The fact that a program error does not significantly change the results is a catastrophe for the computer scientist, because then the error goes unnoticed for years or decades. ! There is at least one bug here We have already passed the variable UTOT via subroutines argument and intent(in/inout). We also made sure that read-only variables are on the left in the arguments and write-only variables are on the right. It is immediately apparent that UTOT is written by EXCHANGE() and applySinks() and that C and CNORM are obvious written by CALC_SPEED(). With a little background knowledge, the first error is immediately apparent: UTOT is changed again after EXCHANGE(). So the other threads don't see the changes from applySinks(). Since it is very unlikely that the nodes of the sink will be ghost nodes contained, this programming error does not lead to incorrect results. (As a reminder: catastrophe.) Now if applySinks() is called before EXCHANGE() to make the changes in UTOT visible to all threads, then you really messed up ;) ! Now its total wrong The reason is: applySinks() uses the CNORM variable via USE,only! However, this is not obvious because it is not explicitly stated in the code. Now UTOT would be used from the current time step and CNORM from the previous time step. Explicitly listing all variables as subroutine arguments read or written in applySinks() would have prevented this error (and a lot of time, money and frustration)! We are not finish yet... The following code is also wrong: ! Still wrong Now applySinks() gets the variable CNORM that was previously calculated by CALC_SPEED(). Here is the code with no more errors: CALL applySinks(IT, ITSUB, DTINT, UTOT) ! Does not use CNORM, the speed is calculated on-the-fly from UTOT as needed for some nodes Furthermore, the explicit listing of all variables that should only be read with intent(in) helps if one of these variables is written to. This is some example we experienced and that is quite actual this kind of stuff happens everywhere! I hope we could help and provide more insights in our concerns. |
Beta Was this translation helpful? Give feedback.
-
The use of use without only can be justified if we use e.g. only some fixed parameters but should be largely avoided. As for the elimination of the given weaknesses it is clearly a big work but we are talking now about coding-standards and at a certain time they need to be fix for the future. There are other points that are clearly more important issues, like memory usage that will also pop up soon. However, since we are now defining code standards we should be as clear as possible and clearly state what we want. This must not happen within days, I guess other developers and users will contribute as well when this is brought up in it's 1st version. So I think it is fair to be pragmatic and just do as much it can be done at once. The fine tuning of the code and the consolidation work is another story that needs much more consideration beyond the coding standards discussed here. I guess when removing all #ifdefs we will have all kind of fun! |
Beta Was this translation helpful? Give feedback.
-
Hi Everyone - Thank you for contributing to the discussion about WW3 code standards! I want to say a special thank you to @DeniseWorthen for the presentation she gave with @mvertens last week and pushing us all towards better code! The EMC code managers (@MatthewMasarik-NOAA and myself) along with the community code managers (@alperaltuntas @ukmo-ccbunney, Erick Rogers, @mickaelaccensi, @thesser1, @sbrus89) created the list of WW3 code style standards we will use for WW3 moving forward based on this discussion. These standards are now on a wiki page and are copied below. Thank you everyone for your participation and contributions to WW3! WW3 Code Style StandardsWhite Space
Line Length
GOTOs:
Modules
Documentation, Headers, Code Comments
Capitalization
Naming Conventions
General “Good Practice”While no effort is being made to update existing code, moving forward the following items, which are considered ‘good practice’ should be followed:
|
Beta Was this translation helpful? Give feedback.
-
Here are a list of proposed code standards for WW3:
Recommendations:
-- ww3_* for programs
-- w3* for shared subroutines and modules
-- wm* for multi- related shared subroutines and modules
Beta Was this translation helpful? Give feedback.
All reactions