(j3.2006) (SC22WG5.4906) [ukfortran] Comment on a comment on the WG5 letterballot on N1947
Van Snyder
Van.Snyder
Thu Jan 17 14:23:01 EST 2013
On Thu, 2013-01-17 at 07:52 -0600, Bill Long wrote:
> > day [1..31]
> > month [1..12]
> > year [1900..2000]
> >
> > and trap invalid days, month and year values.
>
> This seems closer to "bounds" checking where you compare values to
> limit values, none of which involved hardware overflow. With a
> derived type and procedures for assignment and operations, you could
> implement this sort of thing in Fortran.
The need to do this with procedures for assignment is the long-standing
reason that my colleagues have wanted updaters.
If your code was originally written as
read ... date%day
and you later need some range checking, you might change it to
integer :: TempDay
...
read ... tempDay
call storeDay ( date%day, tempDay )
If your code only does this in one place, it's not terribly onerous, but
if you have a data structure that worked by simple assignment, and you
need to change it to representation by a procedure, and assignments to
it are ubiquitous, you would rather not endure the expense of finding
and changing all the assignments to it. This was the reason for
Parnas's advice to hide everything inside of procedures. The reason for
that is that procedure references have the same syntax, regardless of
what the procedure does. Ross, and later Geschke and Mitchell, and
undoubtedly others, recommended changes in programming languages so that
the syntax is invariant, which in turn requires updaters. With a
type-bound updater, one changes the name of the "day" component, makes
it private, and writes reader and updater procedures (or a combined
accessor procedure if the language supports it), and leaves the
statement
read ... date%day
as it is.
This requires allowing to access the reader and updater as date%day, not
requiring it to be accessed as date%day().
More information about the J3
mailing list