[cap-talk] Singletons Considered Harmful

ihab.awad at gmail.com ihab.awad at gmail.com
Tue Mar 30 16:55:19 PDT 2010


On Tue, Mar 30, 2010 at 4:48 PM, Raoul Duke <raould at gmail.com> wrote:
> one is acknowledging that ambientness is useful when one uses instance
> fields. of course, it is all a matter of degree ...

Not really. It's hard to make firm statements when we are talking
about a variety of different languages here, but let's say we are
discussing Java and private instance fields.

The cardinality of allocation of an instance variable is strictly
guarded by the lexical structure of the class. The scope of the
instance variables is restricted to the class instance. Creating a new
instance of the class creates a fresh instance of the instance
variables. It is thus possible for a client of that class to
instantiate the class twice and be assured that each instance can only
communicate with the other, or with any other portion of the world,
only through explicit capabilities provided to that instance.

(Of course, such assurances do not apply in idiomatic Java; they do
apply in Joe-E.)

To leap to another language (say, JavaScript), there is nothing
inherently global about lexically scoped variables in closures:

  function foo(x, y) {
    return function bar(z) {
      return z < x ||  z < y;
    }
  }

Ihab

-- 
Ihab A.B. Awad, Palo Alto, CA


More information about the cap-talk mailing list