Why should i use python if i can use java

Glyph Lefkowitz glyph at twistedmatrix.com
Thu Jun 7 01:43:57 EDT 2001


On 6 Jun 2001, Chris Goringe wrote:

!snip!

> python doesn't [have ...]
> strong typing (love it or hate it...)

Hate it :)

> interfaces (ditto)

Well, python *does* have interfaces, at a much deeper level than Java; you
could think of *everything* in python as going through an interface. What
it doesn't have is interface implementation enforcement; which is nice,
because that means that as long as your classes implement the bits of the
interface you need, minor changes to the code of a library you're using
won't break everything instantly.  I also chuckle to think that the
compiler can tell if I've properly implemented actionPerformed, or if I'm
just stubbing it out by copying the declaration from the interface file.

> an elegant way of implementing singletons (or does it? anyone?)

Aah, the singleton.  Global variables for the new millennium.  First of
all, the singleton "pattern" is usually a bad idea.  If you have a class
that can "only be instantiated once", then you're dealing with per-process
state, and representing it as a class instance can be misleading.  If it's
*not* per-process, then you just have a one-to-many relationship of
objects, not a true "singleton"; attempting to limit this artificially is
a mistake and results in reduced flexibility as well as increased
complexity.

Thankfully, Python provides a much better mechanism for doing so!  
"Modules" are actually singletons wearing funny shoes.  Any "singleton"
state can be specified as a variable in a module. (Which is usually
declared with the 'global' keyword.  Coincidence?)

So, I'd say that this is a flaw with Java not supporting modules, rather
than Python not supporting java's ill-defined crutch which it uses to
cover for its lack of support for first-class namespaces and modules,
fancy terminology notwithstanding.

Since we're on the topic; other design patterns that lurk around
unobtrusively in Python include the "for" keyword, which is really the
"Observer" pattern, the notion of classes as callable, which is the
"Factory" pattern universally applied, and the Strategy pattern
masquerading as first-class functions.  Modules moonlight as the "Facade"
pattern when they're not playing Singleton.  Did guido use the time
machine to get a copy of the GoFBook before he started working on the
first version of Python, or are Patterns just a transparent attempt to
cover for chronically inexpressive languages like C++ and Java which can't
generally implement these mind-numbingly simple constructs in code?  
Inquiring minds want to know.

> a comparable development and debugging environment to JBuilder

Have you used any of the commercial Python IDEs?  PythonWorks or WING IDE?

> but most of all, it doesn't have
> 
> J2EE
> J2ME

Actually it does!  With Jython, you can access any Java API from Python.  
Neat, huh?

> So it still lags Java for seriously scalable enterprise solutions

(Assuming we're talking about [C]Python, since Jython is functionally
equivalent to Java in terms of available technology --) It depends how you
want to scale.  I disagree, but this gets into a very lengthy and
essentially unwinnable argument about development practices.  However,
some "enterprises", such as Google, seem to have implmented really massive
things with Python and I don't think they've noticed that it doesn't work.  
Also, see Zope.

> and for portable device deployment.

Python is currently very difficult to pare down to embedded devices
currently, bit I imagine that it'll be different in 2 years.  However,
once you're up to a certain critical mass, Python's performance tends to
be more deterministic than Java's, so medium-sized "information
appliances" can benefit from Python.


in-languages-that-don't-suck-we-call-"design-patterns"-by-their-real-names-ly
   y'rs,

                      ______      __   __  _____  _     _
                     |  ____ |      \_/   |_____] |_____|
                     |_____| |_____  |    |       |     |
                     @ t w i s t e d m a t r i x  . c o m
                     http://twistedmatrix.com/users/glyph






More information about the Python-list mailing list