Fortran-FOSS-Programmers / Fortran-FOSS-Programmers/Best_Practices

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

Open
#14 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
70
Forks
10
PR merge metrics
No merged PRs in 30d

Description

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.

``` fortran
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 :smile:
### From @tclune suggestion

``` fortran
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)`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.