encapsulation
Andrew J Bromage
andrew@bromage.org
Mon, 8 Jul 2002 09:30:12 +1000
G'day all.
On Mon, Jul 08, 2002 at 09:21:32AM +1200, Tom Pledger wrote:
> That's a matter of opinion. It's strong in all the areas I care
> about, but someone else may find it a pain that there's no way to
> prevent a module from exporting all its evidence declarations.
It _is_ a matter of opinion, and people can agree to disagree on these
points. What it boils down to is: What do you _want_ from
encapsulation?
Encapsulation adds nothing in the way of expressiveness, since every
well-encapsulated program can be transplanted into a language which is
identical except for lack of encapsulation and (except possibly for
namespace pollution issues) it will work just fine.
What it buys you things like robustness and maintainability
(programmers are actively discouraged from using anything but a
module's interface), programmer efficiency (since people are more
expensive than CPU cycles, a bug which the compiler finds is cheaper
to fix than one which a programmer has to hunt down) and so on.
I'm one of those who believe that it's wrong for Haskell to export
evidence declarations, or at least it's wrong for it to happen by
default. When intermodule optimisation is turned off, the interface of
a module should be exactly what the programmer says it is. That way,
changing only the implementation of a module does not trigger a
potentially arbitrary amount of recompilation. This is important
from the point of view of process efficiency. If I, as a programmer,
know that my rebuild will take a while, I can do something else.
However, if I know that I only made an implementation change and this
will not trigger anything else to be recompiled, I can just wait for
it and avoid the cost of two context switches.
Of course this could be easily ameliorated by enforcing the discipline
of writing type declarations on everything, or at least on everything
exported. This is good engineering. However, see the above remarks
on programmer efficiency: accidentally leaving off type declarations is
a bug which a compiler could find much more easily and cheaply than I
could, and it comes for free in most strongly typed languages.
Haskell is the odd one out. While peer group pressure doesn't
constitue an argument, neither is being different just because you
can. :-)
Cheers,
Andrew Bromage