-
Notifications
You must be signed in to change notification settings - Fork 68
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
Transferring fortran90.org "Fortran Best Practices" into a mini-book #246
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Great and valuable content. Thanky you. Is it ready for review? |
The overall structuring looks quite good, but some chapters like integer division and the parallel programming seem very short. For other chapters I'm not sure if they are really suited in a best practice minibook, like interfacing with Python probably deserves its own minibook at some point. I haven't looked over the content in detail yet but already spotted a few issues like broken links, typos, inconsistencies. If I find some time I can give it an editing pass. If this is what we want to do next here. |
This looks great, thank you @vmagnin! Let us know what your plan is. If it is ready for review, we can go over and clean it up. Also let's think about the wording, I already have some ideas for making it more polished and less opinionated, but still pretty clear recommendation how to program in modern Fortran. |
My personal objective was to work on the transfer of the code from fortran90.org to Fortran-lang.org (RST => Markdown mini-book). The community can now review and edit the content in order to integrate it better with the rest of the site. For example, concerning parallel programming, probably it should have its own mini-book, developing OpenMP and MPI, and adding Coarrays. But I guess we should now define what must be done now before accepting the PR and putting the content online, and what could be done later. |
The "Integer division" chapter could be easily enriched into a more general "Integer numbers" and talk about:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a quick indentation pass to change from 4 or 3 space indentation to 2 space indentation similar like in the quickstart guide. Also, I fixed a few minor things I found while going through.
Indentation | ||
----------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have an opinion on tabs in Fortran here?
transfer() Intrinsic Function | ||
----------------------------- | ||
|
||
Before Fortran 2003, the only way to do type casting was using the | ||
`transfer` intrinsic function. It is functionally equivalent to the | ||
method V, but more verbose and more error prone. It is now obsolete and | ||
one should use the method V instead. | ||
|
||
Examples: | ||
|
||
<http://jblevins.org/log/transfer> | ||
|
||
<http://jblevins.org/research/generic-list.pdf> | ||
|
||
<http://www.macresearch.org/advanced_fortran_90_callbacks_with_the_transfer_function> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look good at all, either we describe it ourselves or we remove this section completely.
Complete Example of void \* vs type(c\_ptr) and transfer() | ||
---------------------------------------------------------- | ||
|
||
Here are three equivalent codes: one in C using `void *` and two codes | ||
in Fortran using `type(c_ptr)` and `transfer()`: | ||
|
||
| Language | Method | Link | | ||
|-----------------|----------------------|-----------------------------------| | ||
| C | `void *` | <https://gist.github.com/1665641> | | ||
| Fortran | `type(c_ptr)` | <https://gist.github.com/1665626> | | ||
| Fortran | `transfer()` | <https://gist.github.com/1665630> | | ||
|
||
The C code uses the standard C approach for writing extensible libraries | ||
that accept callbacks and contexts. The two Fortran codes show how to do | ||
the same. The `type(c_ptr)` method is equivalent to the C version and | ||
that is the approach that should be used. | ||
|
||
The `transfer()` method is here for completeness only (before Fortran | ||
2003, it was the only way) and it is a little cumbersome, because the | ||
user needs to create auxiliary conversion functions for each of his | ||
types. As such, the `type(c_ptr)` method should be used instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just move the code snippets here? Linking against gist doesn't really look nice IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some comments. IMO some sections should not be in a "Best Practices" section (e.g., parallel programming, ...)
Point is: it needn't be "one abstract type to encompass all" or bust. | ||
There are natural and viable options between "all" and "none". | ||
|
||
Private Module Variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Private Module Variables | |
III) Private Module Variables |
cleanest way. However, with a bit of thought, usually there is a better, | ||
safer, more explicit way along the lines of II or IV. | ||
|
||
Nested functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested functions | |
IV) Nested functions |
end subroutine foo | ||
``` | ||
|
||
Using type(c\_ptr) Pointer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using type(c\_ptr) Pointer | |
V) Type(c\_ptr) Pointer |
other interface elements), simplest, least bug-prone, and fastest is to | ||
use one of the previous approaches. | ||
|
||
transfer() Intrinsic Function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transfer() Intrinsic Function | |
VI) transfer() Intrinsic Function |
|
||
<http://www.macresearch.org/advanced_fortran_90_callbacks_with_the_transfer_function> | ||
|
||
Object Oriented Approach |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object Oriented Approach | |
VII) Object Oriented Approach |
- add discussion of assumed-rank and assumed-size arrays
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I extended and rewrote a couple of chapters. There is still a lot to do and I haven't gotten around to check every chapter. I would also suggest to remove at least three of the currently added chapters in favor of separate minibooks.
|
I merely scanned the booklet, but I noticed a "gotcha" regarding
floating-point numbers: it looked like a link but it does not lead
anywhere.
And in the chapter on parallel computing I missed a section on coarrays.
But it is taking shape and that is an important thing :)
Op wo 2 jun. 2021 om 15:49 schreef Sebastian Ehlert <
***@***.***>:
… I extended and rewrote a couple of chapters. There is still a lot to do
and I haven't gotten around to check every chapter. I would also suggest to
remove at least three of the currently added chapters in favor of separate
minibooks.
- Introduction
- Fortran Style Guide (sync with updated style guide from fortran-lang/fortran-lang.org#255
<#255>)
- Floating Point Numbers
- Integer Division
- Modules and Programs
- Arrays
- Multidimensional Arrays
- Element-wise Operations on Arrays Using Subroutines/Functions
- Allocatable Arrays
- File Input/Output
- Interfacing with C (remove in favor of separate minibook?)
- Interfacing with Python (remove in favor of fortran-lang/webpage#105
<fortran-lang/webpage#105>?)
- Callbacks
- Type Casting in Callbacks
- Parallel programming (remove in favor of separate minibook?)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#246 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YR4SGOASYO66UY6BYQLTQYZHJANCNFSM43PHAVYA>
.
|
- remove mention of impure newunit function hack
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I'm done for now with editing, the remaining chapters still need some work, though. The typecasting in callbacks chapter is quite a mess and I didn't really grasp what message should be conveyed there, but the external links against gists and blogs are unacceptable IMO, if we can't explain it in the minibook we shouldn't mention it at all. Also, the elemental procedure chapter is really fuzzy and I didn't really got the overall message there, probably requires rewriting from scratch. |
Updating the #build_preview again. |
This PR has been built with Jekyll and can be previewed at: https://fortran-lang.org/pr/246/ |
How do want to move forward here? There are two chapters remaining that require an editing pass. It doesn't have to be a full rewrite, but at least some cleanup should be done. The rest of the minibook should be fine for review now. I see @LKedward and @milancurcic have volunteered for reviewing already. |
Thanks for going over and polishing it @awvwgk. Overall I think the changes make it "less opinionated" which is I think better. I have two comments:
Otherwise the changes are fine with me. |
I would like to join your review if you need me. I have used Fortran since the year 1966 and am especially familiar with old Fortran code. Do you have any use for that expertise? |
@brianconcannon2 yes, we definitely do! Thank you. If you find any improvements in the tutorial, please let us know. (Or if you have any other questions.) |
Thank you @brianconcannon2, I just added you as a reviewer. |
This patch has become stale for quite some time now. Since we already put quite some effort into it I would like to move it forward. Picking this project up again requires quite some time and energy and I only see two minor comments to address so far. Generally I think for a huge patch like this it would be useful to provide comments in Files Changed preferably together with a suggestion. Also, we don't need a complete review of the whole minibook, reviewing a chapter at a time should be sufficient to get this project moving again. |
If we are all more or less ok with how it looks, then I suggest we simply merge it and be done with it. Then we can start sending many subsequent PRs to fix up little things that we find. |
I agree, it would take a long time to review and edit such a large PR. Case in point, I still haven't reviewed it. Let's just merge it and improve with smaller PRs, as @certik suggested. |
I agree with @certik and @milancurcic , |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good enough from me to go in. We can further keep polishing this once merged.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Alright, than I'll go ahead and merge this PR. Thanks everybody for the effort put into this project. |
Transferring the https://www.fortran90.org/src/best-practices.html page, into a mini-book named Fortran Best Practices.
See discussion in issue fortran-lang/webpage#112
A preview of the minibook can be found at https://fortran-lang.org/pr/246/learn/best_practices