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

Declare arguments before local variables #258

Open
Beliavsky opened this issue Jan 2, 2025 · 3 comments
Open

Declare arguments before local variables #258

Beliavsky opened this issue Jan 2, 2025 · 3 comments
Labels
rule A new rule for the linter

Comments

@Beliavsky
Copy link

Fortitude does not complain about the code below, but procedure arguments should be declared before local variables, and arguments should be declared in the order they appear.

module m
implicit none
integer, parameter :: dp = kind(1.0d0)
contains
subroutine mean_sd(x, xmean, xsd)
integer :: i, n
real(kind=dp) :: xsum, xsumsq
real(kind=dp), intent(out) :: xsd, xmean
real(kind=dp), intent(in) :: x(:)
n = size(x)
xsum = 0.0_dp
do i=1,n
   xsum = xsum + x(i)
end do
xmean = xsum/n
xsumsq = sum((x-xmean)**2)
xsd = sqrt(xsumsq/n)
end subroutine mean_sd
end module m
@ZedThree ZedThree added the rule A new rule for the linter label Jan 6, 2025
@ZedThree
Copy link
Member

ZedThree commented Jan 6, 2025

I think this is a fairly obvious style rule we should have

@Beliavsky
Copy link
Author

One caveat is that named constants used in declarations should appear before the declarations, as in

module m
implicit none
contains
subroutine prnt(x)
integer, parameter :: n = 2, dp = kind(1.0d0)
real(kind=dp), intent(in) :: x(n)
print*,x(1)
print*,x(2)
end subroutine prnt
end module m

Thanks for considering so many of my suggestions. They are all based on codes I have seen!

@ZedThree
Copy link
Member

Thanks for considering so many of my suggestions. They are all based on codes I have seen!

They've been really useful, thanks -- keep them coming! Of course, if you also want to implement any of them, that would also be very much appreciated 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule A new rule for the linter
Projects
None yet
Development

No branches or pull requests

2 participants