To: J3 J3/18-249 From: Van Snyder Subject: Supporting generic programming Date: 2018-September-13 Reference: 04-141 Introduction ============ In "On the Criteria for Dividing Programs into Modules" (CACM December 1972), David Parnas pointed out that a change to a program more frequently has a cost proportional to the size of the program than to the size of the change. This is because the syntax to reference an object depends upon its representation. Parnas proposed that access to objects ought to be done only by procedures, hiding the dependence on representation behind the uniform syntax or procedure references. This was the beginning of the practice known as "information hiding," an early development of the larger discipline of software engineering. Douglas T. Ross had observed the problem in 1970. Charles M. Geschke and James T. Mitchell observed the problem in 1975 (IEEE TSE). Both proposed a better solution: The syntax to reference an object ought not to depend upon its representation. Parnas's proposal caught on because it didn't require changes to any existing languages, or converting codes to new languages such as Mesa. Parnas's approach is incomplete, because assignment doesn't have the same syntax as a subroutine reference. It is also less efficient (both in labor and computer resources) than the proposals by Ross, Geschke, and Mitchell. Fortran has the fortunate history that function references and array references have the same syntax. I proposed in 1986 that structure component references ought also to use a function- or array-like reference syntax, but at the time, Parnas's advice hadn't sunk in. The X3J3 consensus was "Fortran programmers want to see what their program is doing and how it is doing it." Proposal ======== Provide a new variety of procedure, called an "updater" in POP-2, that has the same syntax as a function reference, but that can appear in a variable-definition context. When it is invoked, a value is associated to its "transfer" or "receiver" or "acceptor" variable, in the same way that an actual argument is associated to a dummy argument that has INTENT(IN). This might be thought of as a "time reversed" version of a function reference. Alternatively, provide a new variety of procedure, called an "accessor" that explicitly couples processes to reference and update objects, i.e., a function and updater that have the same identifier. In either case, it should be possible to type-bind it, so it has the same syntax as a component reference. This requires to allow to reference a type-bound function that has no arguments other than the passed-object argument without "()". Details and examples of this proposal appear in the PDF files accompanying this paper. They embody both methods to solve the problem. The 1986 proposal to X3J3 included updaters or accessors. In 2004, a limited form of this idea was proposed: If a reference to REAL or AIMAG appears in a variable-definition context with a definable complex variable as its argument, the real or imaginary part of the variable is updated. Instead, the far less general idea of complex part designators was developed.