Skip to content

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

@szaghi

Description

@szaghi

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions