Skip to content
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

Merged
merged 24 commits into from
Sep 5, 2021
Merged

Transferring fortran90.org "Fortran Best Practices" into a mini-book #246

merged 24 commits into from
Sep 5, 2021

Conversation

vmagnin
Copy link
Member

@vmagnin vmagnin commented Apr 23, 2021

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

@awvwgk

This comment has been minimized.

@github-actions

This comment has been minimized.

@jvdp1
Copy link
Member

jvdp1 commented Apr 23, 2021

Great and valuable content. Thanky you. Is it ready for review?

@awvwgk
Copy link
Member

awvwgk commented Apr 23, 2021

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.

@certik
Copy link
Member

certik commented Apr 23, 2021

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.

@vmagnin
Copy link
Member Author

vmagnin commented Apr 24, 2021

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.

@vmagnin
Copy link
Member Author

vmagnin commented Apr 25, 2021

some chapters like integer division and the parallel programming seem very short.

The "Integer division" chapter could be easily enriched into a more general "Integer numbers" and talk about:

  • the different kinds of integers (and kinds defined in iso_fortran_env),
  • and their ranges and the problems when you go out of range: beginners knowing only Python may not be aware of those problems, as in Python the number of bytes is automatically adapted as needed... No limit!
  • inquiry functions like huge(),
  • the fact that there is no unsigned integers (perhaps in Fortran 202x?) in Fortran, a big difference for people knowing C,
  • ...

@LKedward LKedward self-requested a review April 26, 2021 07:32
@milancurcic milancurcic self-requested a review May 1, 2021 16:03
Copy link
Member

@awvwgk awvwgk left a 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.

Comment on lines +40 to +41
Indentation
-----------
Copy link
Member

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?

Comment on lines +373 to +387
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>
Copy link
Member

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.

Comment on lines +474 to +494
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 &nbsp; | Method | Link |
|-----------------|----------------------|-----------------------------------|
| C | `void *` | <https://gist.github.com/1665641> |
| Fortran | `type(c_ptr)` &nbsp; | <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.
Copy link
Member

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.

Copy link
Member

@jvdp1 jvdp1 left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Nested functions
IV) Nested functions

end subroutine foo
```

Using type(c\_ptr) Pointer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
transfer() Intrinsic Function
VI) transfer() Intrinsic Function


<http://www.macresearch.org/advanced_fortran_90_callbacks_with_the_transfer_function>

Object Oriented Approach
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Object Oriented Approach
VII) Object Oriented Approach

@awvwgk

This comment has been minimized.

@github-actions

This comment has been minimized.

@awvwgk
Copy link
Member

awvwgk commented Jun 2, 2021

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.

@arjenmarkus
Copy link
Member

arjenmarkus commented Jun 2, 2021 via email

- remove mention of impure newunit function hack
@awvwgk

This comment has been minimized.

@github-actions

This comment has been minimized.

@awvwgk
Copy link
Member

awvwgk commented Jun 3, 2021

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.

@awvwgk awvwgk added help wanted Extra attention is needed learn Related to the learning resources labels Jun 5, 2021
@awvwgk
Copy link
Member

awvwgk commented Jun 8, 2021

Updating the #build_preview again.

@github-actions
Copy link

github-actions bot commented Jun 8, 2021

This PR has been built with Jekyll and can be previewed at: https://fortran-lang.org/pr/246/

@awvwgk
Copy link
Member

awvwgk commented Jun 17, 2021

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.

@certik
Copy link
Member

certik commented Jun 17, 2021

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.

@brianconcannon2
Copy link

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?

@certik
Copy link
Member

certik commented Jun 27, 2021

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

@milancurcic
Copy link
Member

Thank you @brianconcannon2, I just added you as a reviewer.

@awvwgk
Copy link
Member

awvwgk commented Sep 4, 2021

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.

@certik
Copy link
Member

certik commented Sep 4, 2021

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.

@milancurcic
Copy link
Member

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.

@vmagnin
Copy link
Member Author

vmagnin commented Sep 4, 2021

I agree with @certik and @milancurcic ,
once online, it will be easier to review it (and by more people once announced on the Discourse), and I think we will gain a new motivation for that task, knowing it's online!

Copy link
Member

@certik certik left a 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.

@awvwgk awvwgk removed the help wanted Extra attention is needed label Sep 5, 2021
@awvwgk

This comment has been minimized.

@github-actions

This comment has been minimized.

@awvwgk
Copy link
Member

awvwgk commented Sep 5, 2021

Alright, than I'll go ahead and merge this PR. Thanks everybody for the effort put into this project.

@awvwgk awvwgk merged commit e3373ca into fortran-lang:master Sep 5, 2021
@vmagnin vmagnin deleted the fortran90org branch September 5, 2021 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
learn Related to the learning resources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants