[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modules don't provide the functionality of dynamic binding

Scott recently touted a flexible module facility as a substitute for
dynamic binding.  He also divided uses of dynamic binding into three
categories, and claimed that modules worked "better", especially for
large programs, in those cases.  In this message, I hope to convince
you that using modules to replace dynamic binding in at least one of
those cases requires dynamics....  (This is not intended as an
argument against a flexible module facility.  I think it's a wonderful
tool for other problems.)

Scott said that dynamics were often used to pass arguments indirectly;
the simple case is that A calls B and B calls C, but A wants to
provide input to C that it doesn't want to pass through B.  I agree.

Scott's proposed solution was for A to construct (using the module
facility), a custom version of C that has the arguments that A wants
to provide and have B call that procedure.  The problem with that
is telling B which C to call.

To illustrate that, let's look at a more complex example.  As above, A
wants to call C indirectly through B, without letting B see all of C's
input.  (I guess I should clarify what "see" means.  It means that one
can examine B's text to determine whether or not it looks at the
variable in question.  If dynamics are data objects, this doesn't
work, but ....)  Since we're concerned with programming in the large,
let's include A', which also wants to call C indirectly through B, and
A' wants to provide the same input to C that A did.  (In a related
case, A and A' are providing default values for different input to C.)

If A and A' construct their own versions (using the module system) of
C, then they have to tell B to call the right one.  One way is for
them to pass it.  This "works", but misses the point and is awkward
for more complex examples.  The alternative is for them to redefine
C's (global to B) definition.  Maintaining that redefinition
correctly, when B is not defined within A, requires simulating