Strong vs weak encapsulation [correction]

# David-Sarah Hopwood (15 years ago)

On 2010-12-21 08:27, David-Sarah Hopwood wrote:

The private names and soft field proposals are similar in the visibility mechanisms they can simulate, but soft fields are slightly more general. In either proposal, visibility can be restricted to a particular lexical scope. In the soft fields proposal, because SoftFields are first-class values, it can also be restricted to any set of objects that can get access to a given SoftField.

Correction: the #.id syntax also allows private names to be treated as first-class values, so the proposals are equivalent in this respect.

I don't claim this to be a critical benefit, but it is occasionally useful in object-capability programming. For example, in www.erights.org/elib/capability/ode/ode-capabilities.html#simple-money, a Purse of a given currency is supposed to be able to access a private field of other Purses of the same currency, but not other Purses of different currencies. The implementation at www.eros-os.org/pipermail/cap-talk/2007-June/007885.html uses WeakMaps to do this, and could just as well use soft fields

or private names