One thing I miss a lot about Fortran compared to other languages I use is to declare variables at any point in time, and to have those variables automatically scoped to the block in which they’re declared (in an if, for example). This can be great for locality, descriptive names, etc., but in Fortran the only way to achieve this that I’m aware of is the block construct. The problem with that is that standard indentation would cause you to double indent the contents.
if (something) then
block
integer :: blah
blah = foo( &
bar, &
baz, &
whatever &
)
! use blah
! ...
end block
end if
I came up with this and I can’t decide if I hate it or love it. Thoughts?
if (something) then; block
integer :: blah
blah = foo( &
bar, &
baz, &
whatever &
)
! use blah
! ...
end block; end if
I voted not cursed. In general indentation is good, but multiple levels of indentation can lead to long lines or continuation lines, which reduce readability.
Also possible is
if (something) then
block
integer :: blah
blah = foo( &
bar, &
baz, &
whatever &
)
! use blah
! ...
end block
end if
What would really be great is if one didn’t need explicit block/endblock at all inside block IFs, block DO loops and so on. But this has been debated ever since ALGOL-60 came out…
I actually think that it’s perfectly fine to NOT indent some constructs when it does not alter the readability (typically when they begin and end together). Similarly, I sometimes don’t indent perfectly nested loops:
do i = ...
do j = ...
do k = ...
a(k,j,i) = ...
end do
end do
end do
But:
do i = ...
x = some_function(i)
do j = ...
do k = ...
a(k,j,i) = ...
end do
end do
end do