Why should i use python if i can use java

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sun Jun 10 15:45:05 EDT 2001


07 Jun 2001 09:49:36 -0700, Don Dwiggins <dwig at advancedmp.net> pisze:

>    Use the Singleton pattern when
>    - there must be exactly one instance of a class, and it must be 
>      accessible to clients from a well-known access point.

One in what? In the world? In all runs of the process? In the current
run of the process? In a large subcomputation?

Why would you create an arbitrary scope of life?

>    - when the sole instance should be extensible by subclassing, and
>      clients should be able to use an extended instance without modifying
>      their code.

If subclassing would alter the behavior of the object - what would
happen if several clients alter it in incompatible ways?

Global implicit state rarely makes sense; mainly for interfacing
with the OS and supporting the runtime system of the language. It's
inflexible - with global state you can't take the meaning of the
program and execute it twice in the process, you can't take a part
of the program and execute it in a different context (it's will not
be self-contained), threading may be problematic.

It's nothing wrong when a stateless data is global. For example
function definitions and class definitions are almost always
stateless. Immutable or lazily evaluated data which doesn't depend
on the process environment is stateless. These are fine because
it doesn't matter when it's created and in how many copies - they
statically define the program.

But state, i.e. objects with meaningful identity, should be managed
explicitly. As a quick hack in small scripts it can be convenient to
have a global variable or two, but it's inflexible.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list