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

Use keyword argument calling-style for all optional arguments in procedures callings #14

Open
szaghi opened this issue Jan 21, 2016 · 0 comments

Comments

@szaghi
Copy link
Member

szaghi commented Jan 21, 2016

For readability/debugging/robustness/safeness (what else?) purposes it could be interesting to add a guideline about

use keyword argument calling-style for all optional arguments in procedures callings

e.g.

subroutine foo(a, b, c)
  integer, intent(in) :: a
  real, intent(in) :: b
  logical, optional, intent(in) :: c
end subroutine foo
...
call foo(x, y, z) ! bad
call foo(a=x, b=y, c=z) ! good 

The discussion is open 😄

From @tclune suggestion

module Foo_mod
   implicit none
   private
   public :: Foo

   type :: Foo
      integer :: i
   contains
      procedure :: some_method
   end type

   ! This type is PRIVATE
   type :: Unusable
   end type

contains
   subroutine some_method(this, unused, opt1, opt2)
      class (Foo), intent(inout) :: this
      type (Unusable), optional, intent(in) :: unused
      real, optional, intent(in) :: opt1
      integer, optional, intent(in) :: opt2
    end subroutine some_method
end module Foo_mod

This enforce to call myfoo%some_method(opt1=x, opt2=y)

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

1 participant