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

Mean example is too verbose #6

Open
milancurcic opened this issue Dec 14, 2017 · 2 comments
Open

Mean example is too verbose #6

milancurcic opened this issue Dec 14, 2017 · 2 comments

Comments

@milancurcic
Copy link

milancurcic commented Dec 14, 2017

I understand the advantage of demonstrating the power of coretran on a very simple example, however the native Fortran code for the mean example is unnecessarily verbose and misrepresents the level of verbosity of Fortran. The following can make it much more succinct:

  • No need to explicitly allocate - use automatic allocation on assignment.
  • No need to explicitly deallocate at the end of the program - let the array get cleaned-up by the compiler.
  • No need to explicitly re-cast integer to real - let the compiler do the type coercion.

The equivalent and correct example:

program theMean_program
use, intrinsic :: iso_fortran_env, only: real64, int32
implicit none
real(real64), allocatable :: a(:)
real(real64) :: theMean
integer(int32) :: i, istat, N
N=1000

! Create numbers from 1 to N
a = [(real(i,kind=real64), i=1,N)]

! Compute the mean
theMean = sum(a)/N

end program
@leonfoks
Copy link
Owner

Thanks for the great points and I agree that the small example doesn't even do the idea of coretran any justice let alone newer aspects of Fortran. I've been meaning to update this for a while.

In my opinion, I would consider your use of the very succinct aspects of Fortran to be modern. Since i'm coming from a back ground of teaching modern Fortran to people who are not used to modern Fortran at all, I left the older styles in. This makes the example more accessible to people who get confused by implicit do loops on assignment and even vectorized notation.

Perhaps I should just take out the comparison of "old" and "coretran" code, and simply show some examples of using coretran like in the rest of the docs.

@leonfoks
Copy link
Owner

Also, just to comment on your three points above.

  • I've had some weird memory issues when relying on automatic allocation and large codes. So I like to be explicit with allocation and deallocation.
  • I once thought the same thing about letting clean up deallocate out-of-scope variables. Then I said the same thing at a class up at NCAR in Boulder. The response was "and you trust it?" So i've been explicit about deallocating memory ever since.
  • I'm mainly explicit about conversions because I hate getting warnings when i'm compiling code under debug flags. Plus the more explicit you are the better....right?

Thanks for your feedback!

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