(j3.2006) How to assign to the declared-type part of a polymorphic allocatable array?

Van Snyder Van.Snyder
Thu Sep 22 19:00:20 EDT 2016


On Thu, 2016-09-22 at 21:07 +0000, Clune, Thomas L. (GSFC-6101) wrote:
> I also think a ?setter? method would accomplish what you want:
> 
> call geo%set_h_t(z%ZOT_to_geo())

Starting in 1986, I advocated for uniform syntax and updaters in
Fortran.  Updaters can be thought of as the reverse of functions.  They
"absorb" a value instead of producing one.  Also starting on page 38 of
97-114r2.

Updaters appear in a variable-definition context, but otherwise look
like a function reference.  Ideally, they can have the same name as a
function that provides a value instead of absorbing it.

So you'd have something like

  geo%h_t_part() = z%ZOT_to_geo()
...
  print *, geo%h_t_part()

or, even better, without the empty parentheses.  The reason for not
wanting parentheses is that if you have a component for which new
requirements cause it to be changed to a function/updater, you don't
need to find every reference to it and add the empty parentheses.  Or if
you invent a simplicication that allows it to be a component instead of
a function/updater you don't have to find every reference and remove the
empty parentheses.

The goal is to reduce the cost of maintaining software.  For long-lived
projects, up to 90% of the "ownership cost" is maintenance.

Douglas T. Ross wrote about this in 1969 in a chapter in a book entitled
"Software Engineering," for which J. T. Tou was editor.  Geschke and
Mitchell wrote about it in 1975 in Volume 1 of IEEE Transactions on
Software Engineering.  The solution that caught on, because it worked in
every language, rather than requiring languages to provide it, was David
Parnas's advice in CACM in December 1970 ("On the Criteria for Dividing
Programs into Modules") to put everything in tiny little procedures.
This has the defect that you need

  call geo%set_h_t(z%zot_to_geo())
and
  print *, geo%get_h_t()

which are not obviously anti-symmetric, or even related.

The argument against uniform syntax at the 1986 meeting in Albuquerque
was "Fortran programmers want to see what their program is doing."
According to Parnas, this is exactly what you DO NOT want to see.  It
increases ownership cost.  Brian Smith, John Reid, and Rex Paige liked
my idea, but the other forty or so denizens of X3J3 didn't.

You might recall that I advocated a few years ago that aimag and real
ought to be updaters if they appear in a variable-definition context and
their arguments are of complex type.  So you could have

  y = aimag(z)
and
  aimag(z) = y

Instead we got the %im and %re things that look sort of like components
but aren't called that.





More information about the J3 mailing list