On Saturday, August 17, 2019 at 9:19:15 AM UTC-4, Thomas Koenig wrote:
> ..
https://j3-fortran.org/doc/year/19/19-188.pdf does a pretty good
> job (IMHO) pointing out what went wrong in other languages, and
> what can be made better in Fortran as a result.
To write the paper "does a .. good job pointing out what went wrong in other languages" is NOT right. Readers would do well to refer back to Steve Lionel's comment in the previous post, "I would hesitate to label things "correct" or "wrong". As I understand it, some approaches have limitations that didn't become apparent until some time after they were implemented. That doesn't make them wrong. (For an example of this from Fortran, look at FORALL.) "
On Saturday, August 17, 2019 at 9:08:06 AM UTC-4, Steve Lionel wrote:
> ..
> I expect WG5 to converge on an approach that draws from the best of
> other languages, fits well with Fortran, and solves major issues Fortran
> programmers encounter today. Will it solve everyone's issues? Unlikely.
> ..
The question for WG5 remains WHEN will enhanced generics appear in Fortran, perhaps in 202y? And in which case *reliable* processor (compiler) implementations will become available in 2045, if at all?
Before attempting to answer that question, WG5 should really ask itself 2 fundamental questions:
For whom Fortran? For what?
Readers should take note of 2 points:
1) On one hand the ISO IEC standard is entirely silent on the above 2 questions but unabashedly presents Fortran as some general-purpose language for everyone for everything, including for unicorns for the purpose of making skittles!
2) On the other hand, every decision and direction taken by the committee has to satisfy the interests of certain TENURED institutional reps toward a few long-standing programs toward particular applications in so-called scientific and numerical computing and their suppliers, the compiler vendors, who only see certain limited returns on their efforts with Fortran language and thus are inclined to adopt minimalism and where "performance and backward compatibility", like industrial SAFETY post-Bhopal in chemical industry, are wielded like the double-edged sword: one can "kill" any and all feedback from ordinary practitioners with these 2 undeniable notions OR when a clique forms with a strong interest in something like SPMD with PGAS approach using COARRAYS, one can sell any idea using such considerations even if the work can be of little benefit to so many in the computing world where Fortran is mostly in a few libraries and that "single program" in SP can be anything but a Fortran main program i.e., a 3rd-party simulator, a spreadsheet program, a web browser, some opaque thingy running on the cloud, ...
All the while, the computing world keeps advancing rapidly but where
NO LARGE, NEW programs, worthy of any consideration especially in industry, get developed in Fortran, period.
The above points are especially important in the case of generics: because if Fortran is truly intended to be a general-purpose language for a wide variety of applications as mentioned in point 1, then considerations involving any issues faced by the practitioners of C++ and Java might become meaningful.
However, like with everything else particularly OO, if Fortran is immediately predisposed to including only the MINIMUM facilities in the language for specific needs as envisioned by those reps with their "scientific and numerical computing" applications with considerations of "performance and backward compatibility", then why go around bad-mouthing C++, Java, etc. at all? That is, when the "scientific and numerical computing" developers using these other languages mostly adopt a small set of the Templates/Generics features of these languages where the stated issues such as in paper 19-188 are of little relevance.
Separately, readers here and especially WG5 (should it be serious about generics) will take take note there is a language system and an implementation framework that gets *GENERICS just about RIGHT* and that is Microsoft with their .NET system and C# and Visual Basic languages.
C# and Visual Basic are reasonably close to efficient and practicable examples of languages that draws from the best of other languages such as C++ and Java, adopts aspects that fit well with their existing platforms, and solves major issues faced earlier by their programmers. C# and Visual Basic find ever-increasing applications, especially in industry, in many domains including the "scientific and numerical computing" ones.
So what would it take for WG5 to take a close look at generics in Microsoft C#/Visual Basic.NET? I ask given the tacit and persisting bias I notice against Microsoft's solutions by many, one which can be especially VIRULENT among the academia (it's rather strange the lead author of paper 19-188 makes no reference to either C# or Visual Basic in that paper) but also by certain influencers in connection with Fortran. It appears an uphill battle, nearly an impossible one, to "market" .NET languages successfully as only examples to look at and to give them a basic (pun intended) level of consideration toward feature development in Fortran.
Features delayed are features denied. Excluding generics from Fortran 202x is already doing an indescribable amount of disservice to practitioners of Fortran.
But that WG5 won't agree to provide even an intrinsic "swap" procedure in Fortran 202x (a la std::swap in C++) that can swap arguments of *any type* on account of bureaucratic consideration the work-list had to be locked in essentially by early February of 2018 is of further shame. Intrinsic 'swap' in the Fortran standard will prove valuable no matter what form the future facility with generics takes in Fortran but this intrinsic can allow users to consider *generic* algorithms in their code by at least 2032 instead of 2045! e.g., a user can implement a quick sort routine with highly reduced code duplication to sort arrays of *any* type (with derived types, the user will likely have to provide the means to compare the types of course).
On the other hand, to say "one can do a lot with Fortran today" which is really saying the coders have to write LOTS and LOTS of code for the most basic and mundane of tasks - see below - is giving NO RESPECT whatsoever to any industry, particularly the time and labor of coders which are always the most valuable assets:
--- Example of RIDICULOUS code duplication with current Fortran ---
module m
! Dozens of lines of code for a 'generic' swap of processor-supported
! integer kinds and default real and logical and character (with further
! restrictions on length).
use, intrinsic :: iso_fortran_env, only : integer_kinds
implicit none
private
generic, public :: swap => swap_ik1, swap_ik2, swap_ik3, swap_ik4, swap_real, swap_char, swap_bool
contains
elemental subroutine swap_ik1( lhs, rhs )
! Argument list
type(integer(integer_kinds(1))), intent(inout) :: lhs
type(integer(integer_kinds(1))), intent(inout) :: rhs
! Local variables
type(integer(integer_kinds(1))) :: temp
! common instructions can be in an INCLUDE file
temp = lhs
lhs = rhs
rhs = temp
end subroutine
elemental subroutine swap_ik2( lhs, rhs )
! Argument list
type(integer(integer_kinds(2))), intent(inout) :: lhs
type(integer(integer_kinds(2))), intent(inout) :: rhs
! Local variables
type(integer(integer_kinds(2))) :: temp
temp = lhs
lhs = rhs
rhs = temp
end subroutine
elemental subroutine swap_ik3( lhs, rhs )
! Argument list
type(integer(integer_kinds(3))), intent(inout) :: lhs
type(integer(integer_kinds(3))), intent(inout) :: rhs
! Local variables
type(integer(integer_kinds(3))) :: temp
temp = lhs
lhs = rhs
rhs = temp
end subroutine
elemental subroutine swap_ik4( lhs, rhs )
! Argument list
type(integer(integer_kinds(4))), intent(inout) :: lhs
type(integer(integer_kinds(4))), intent(inout) :: rhs
! Local variables
type(integer(integer_kinds(4))) :: temp
temp = lhs
lhs = rhs
rhs = temp
end subroutine
elemental subroutine swap_real( lhs, rhs )
! Argument list
type(real), intent(inout) :: lhs
type(real), intent(inout) :: rhs
! Local variables
type(real) :: temp
temp = lhs
lhs = rhs
rhs = temp
end subroutine
elemental subroutine swap_char( lhs, rhs )
! Constraint: lhs and rhs must have same length
! Argument list
type(character(len=*)), intent(inout) :: lhs
type(character(len=len(lhs))), intent(inout) :: rhs
! Local variables
type(character(len=len(lhs))) :: temp
temp = lhs
lhs = rhs
rhs = temp
end subroutine
elemental subroutine swap_bool( lhs, rhs )
! Argument list
type(logical), intent(inout) :: lhs
type(logical), intent(inout) :: rhs
! Local variables
type(logical) :: temp
temp = lhs
lhs = rhs
rhs = temp
end subroutine
end module
program p
use m, only : swap
blk1: block
integer, parameter :: IP = selected_int_kind( r=2 )
integer(IP) :: a, b
print *, "Block 1"
a = 2_ip
b = 3_ip
call swap( a, b )
print *, "a = ", a, "; expected is 3"
print *, "b = ", b, "; expected is 2"
end block blk1
print *
blk2: block
integer, parameter :: IP = selected_int_kind( r=10 )
integer(IP) :: a, b
print *, "Block 2"
a = (2_ip)**42
b = (2_ip)**43
call swap( a, b )
print *, "a = ", a, "; expected is ", (2_ip)**43
print *, "b = ", b, "; expected is ", (2_ip)**42
end block blk2
print *
blk3: block
use, intrinsic :: iso_c_binding, only : IP => c_int
integer(IP), allocatable :: a(:), b(:)
integer :: i
print *, "Block 3"
a = [ 101, 102, 103 ]
b = [( a(i), i=size(a),1,-1 )]
call swap( a, b )
print *, "a = ", a, "; expected is ", [ 103, 102, 101 ]
print *, "b = ", b, "; expected is ", [ 101, 102, 103 ]
end block blk3
print *
blk4: block
real :: a, b
print *, "Block 4"
a = -99.0
b = 99.0
call swap( a, b )
print *, "a = ", a, "; expected is ", 99.0
print *, "b = ", b, "; expected is ", -99.0
end block blk4
print *
blk5: block
character(len=:), allocatable :: a, b
print *, "Block 5"
a = "foo"
b = "bar"
call swap( a, b )
print *, "a = ", a, "; expected is ", "bar"
print *, "b = ", b, "; expected is ", "foo"
end block blk5
stop
end program p
--- End example ---
Upon execution of the program compiled using a processor offering certain Fortran 2018 support such as enhancements to the GENERIC statement:
Block 1
a = 3 ; expected is 3
b = 2 ; expected is 2
Block 2
a = 8796093022208 ; expected is 8796093022208
b = 4398046511104 ; expected is 4398046511104
Block 3
a = 103 102 101 ; expected is 103 102 101
b = 101 102 103 ; expected is 101 102 103
Block 4
a = 99.00000 ; expected is 99.00000
b = -99.00000 ; expected is -99.00000
Block 5
a = bar; expected is bar
b = foo; expected is foo