newbie question

Delaney, Timothy tdelaney at avaya.com
Thu Aug 23 01:16:39 EDT 2001


> Anyway, the issue is what is the future of jpython, and what 
> is its future
> relative to JSP (and also relative to javascript, which is 
> also developing
> into its own full language)? Also, what role should each 
> language play in a
> design, if they are used together. I suggest looking on-line 
> for computer
> magazine articles rather than relying on user's opinions 
> (including myself).
> Try to find sources that aren't focused solely on java (such as 'java
> world') or python (such as 'python world'?). No doubt jpython 
> will fill a
> specific market niche just like java. However, I've seen many 
> companies go
> belly up and I wonder about jpython. How can they compete 
> with an upcoming
> powerhouse like JSP in the long term? Java will be very time 
> consuming to

Methinks you have completely the wrong idea about Jython (note - the current
version is called Jython - JPython is a trademark of CNRI).

Jython is simply an implementation of the Python language running on the
Java VM. As such it behaves the same as CPython in most ways (however, it
uses the VM's garbage collection, and there are a few other differences). It
is not intended to be a competitor to JSP, or anything else. It can be used
quite happily in conjunction with those technologies however.

I personally am using Jython right this instant to prototype a Swing
application (well, and refreshing myself on Swing). I find it is a lot
faster to code and easier to read the prototype in Python than in Java. For
example, I don't need to worry about setting up my ActionListeners, etc ... 

   import javax.swing as swing

   def func (event):
      print 'Hello, world!'

   panel = swing.JPanel()
   panel.add(swing.JButton('OK', actionPerformed=func))

and a proxy ActionListener is automatically set up which calls the specified
func when an ActionEvent is received.

The corresponding Java is along the lines of

   import javax.swing.*;
   import java.awt.event.*;

   class MyActionListener implements ActionListener
   {
      public void actionPerformed (ActionEvent  event)
      {
         System.out.println("Hello, world!");
      }
   }

   JPanel   panel    = new JPanel();
   JButton  button   = new JButton('OK');

   button.setActionListener(new MyActionListener());

and I'm pretty sure I've forgotten a throws clause. That's 5 useful lines to
8 (using .* imports in Java), and I don't have crufty braces breaking up the
look of the code.

In addition, I don't need to compile each Python file to a Java class before
I can use it - leading to a faster prototype/test cycle. And I am guaranteed
than any changes to other Python modules will be picked up on the next run -
unlike Java where any changed files need to be recompiled - and it's likely
that some will be missed if you compile with dependencies.

Finally, I can compile all the Python code to Java .class files, package
them up in a .jar, etc - just like I can do with Java code.

When you look at it that way, you start to ask yourself why there's a need
to code it in Java at all ...

Tim Delaney




More information about the Python-list mailing list