XML is a popular medium for representing, transforming, and sharing data among applications. Common examples include configuration files for web applications, inter-application messaging using SOAP, and user interface transformation using XSLT. Some say that XML is so great because it's "everything and nothing." This has led to applications of XML to areas outside of its element. XML is often used as the basis of a custom scripting language. As a result, common programmatic constructs are duplicated and the code is difficult to understand; XML tools are not designed to support this.
In this article, I will show a few examples from the Java community using XML as a scripting language. I will also show those same examples in Jython, in order to demonstrate the usefulness of a scripting language. There are many other Java-based scripting languages. Jython is simply Python implemented in Java (lagging a few releases behind). Jython and Java objects can communicate without any special bindings. This means Jython objects can extend Java objects and more. Jython syntax will feel familiar, with notable exceptions, such as: lines do not end with semicolons, and tabs, rather than curly braces, are used to delineate code blocks. This article does not suggest that Jython is better than XML, but rather that each is particularly suited for solving different problems. This article explores some common tasks performed with XML and how they might be better implemented in a Java scripting language. A future article will focus on the actual implementation of one of these tasks, showing in detail the benefits of Java scripting.
Scripting Tests with XML and Jython
We'll start by exploring a testing infrastructure that my company is developing. This system was first built using XML and then reimplemented and extended using Jython. These two examples highlight some of the problems encountered when you implement scripts in XML. In this case, we will see how these limitations can be addressed by swapping out the XML for a full-powered scripting language such as Jython.
Replacing an XML Test Script with Jython
In this first example, you will already see a slight benefit in replacing XML code with Jython. Because the XML maps so clearly to the Jython, you will get a clear idea of what is going on. The Jython code is cleaner and more familiar to Java programmers due, in this case, to the built-in ability to define and use variables. Consider this XML implementation of a test of a stock trading system: two traders log in, each with Yahoo (nyse:YHOO) stock to trade. The trade is executed and both traders log out. To avoid duplicated data, we have introduced a data object used to define all of the stocks in one place so they can be referenced by the same stock objects throughout the test.
In this test, ${YHOO} references the YHOO stock defined in the <stocks> element at the beginning of <test>. The introduction of variables eliminates duplicated code but requires additional code in the XML parser for the tests to be parsed and function properly. In addition, the presence of stock objects introduces issues of scope. If one test references another test and each has an object with the same name, which takes precedence? This requires technical specification for scooping, and even more custom code in the parser and controller to make the tests function properly. The issue of argument passing came up and we implemented that as well, which required another set of technical requirements and code changes in the parser and controller.
It is easy to get trapped in this sort of loop. You create incremental fixes to your current problems and forget to stand back and take another look from the broader perspective. Fortunately for those of us working on this particular project, a few forward-thinking team members pointed out that we were creating an entire language in XML and suggested that we move to a full-blown scripting language like Jython. That way, all of the scooping, variable passing, and other programmatic constructs could be handled by language experts, and we could spend our time writing the testing system instead of a proprietary XML-based language.
The Jython code for this example is quite a bit cleaner than the XML. All of the variable parsing, scooping, passing, assigning, and referencing code that we had to write in the parser and controller came free with Jython.
Reducing Tedium in Testing
The benefits of using a scripting language go far beyond simply getting variable functionality for free. The following example shows how we benefit from different built-in collections and iteration constructs. In this example, we had a set of five user-configurable default response messages in our client application, and each message had seven steps to verify that the field was being retrieved and edited properly. As your eyes glaze over in the following listing, notice that the seven steps have to be repeated almost verbatim, changing values at each pass. Here is the complete test to verify all five fields:
<test>
<login trader="Trader1" password="pswd"/>
<verify-default-response field="default1" >
Hello McFly
</ verify-default-response>
<verify-default-response field="default1" shouldFail="true">
New Message
</ verify-default-response>
<edit-default-response field="default1">
New Message
</ set-default-response>
<verify-default-response field="default1">
New Message
</ verify-default-response>
<verify-default-response field="default1" shouldFail="true">
Hello McFly
</ verify-default-response>
<edit-default-response field="default1" >
Hello McFly
</ verify-default-response>
<verify-default-response field="default1">
Hello McFly
</ verify-default-response>
<verify-default-response field="default2" >
Wazzzup
</ verify-default-response>
<verify-default-response field="default2" shouldFail="true">
New Message
</ verify-default-response>
<edit-default-response field="default2">
New Message
</ set-default-response>
<verify-default-response field="default2">
New Message
</ verify-default-response>
<verify-default-response field="default2" shouldFail="true">
Wazzzup
</ verify-default-response>
<edit-default-response field="default2" >
Wazzzup
</ verify-default-response>
<verify-default-response field="default2">
Wazzzup
</ verify-default-response>
<verify-default-response field="default3" >
Your mother was a hamster
</ verify-default-response>
<verify-default-response field="default3" shouldFail="true">
New Message
</ verify-default-response>
<edit-default-response field="default3">
New Message
</ set-default-response>
<verify-default-response field="default3">
New Message
</ verify-default-response>
<verify-default-response field="default3" shouldFail="true">
Your mother was a hamster
</ verify-default-response>
<edit-default-response field="default3" >
Your mother was a hamster
</ verify-default-response>
<verify-default-response field="default3">
Your mother was a hamster
</ verify-default-response>
<verify-default-response field="default4" >
Hey Josephus, Hey @$#!
</ verify-default-response>
<verify-default-response field="default4" shouldFail="true">
New Message
</ verify-default-response>
<edit-default-response field="default4">
New Message
</ set-default-response>
<verify-default-response field="default4">
New Message
</ verify-default-response>
<verify-default-response field="default4" shouldFail="true">
Hey Josephus, Hey @$#!
</ verify-default-response>
<edit-default-response field="default4" >
Hey Josephus, Hey @$#!
</ verify-default-response>
<verify-default-response field="default4">
Hey Josephus, Hey @$#!
</ verify-default-response>
<verify-default-response field="default5" >
Ni!
</ verify-default-response>
<verify-default-response field="default5" shouldFail="true">
New Message
</ verify-default-response>
<edit-default-response field="default5">
New Message
</ set-default-response>
<verify-default-response field="default5">
New Message
</ verify-default-response>
<verify-default-response field="default5" shouldFail="true">
Ni!
</ verify-default-response>
<edit-default-response field="default5" >
Ni!
</ verify-default-response>
<verify-default-response field="default5">
Ni!
</ verify-default-response>
<logout trader="Trader1"/>
</test>
This is not an optimal solution. Writing this test requires a very time-consuming and error-prone process of copying and pasting the test block and replacing the test messages. This poses a number of additional problems, including the fact that there is no centralized message list for an easy default message, making it hard to maintain. Additionally, it is difficult to understand what the test is doing because of its verbosity. Of course, there are other XML tools available that will allow us to code this example differently, but let us look, instead, at using a language built for scripting.
Jython test code for this example is extremely simple. We can leverage the benefits of a scripting language and loop through the messages, calling the same function for each one. Additionally, we can abstract the set of default messages into a Jython dictionary (similar to a Java hashtable). Here is the Jython version:
defaultMessages = {
"message1": "Hello McFly",
"message2": "Wazzzup",
"message3": "Your mother was a hamster",
"message4": "Hey Josephus, Hey @$#!,
"message5": "Ni!"
}
def EditNegotiationChatMessagesTest():
loginTraderTask(trader="Trader1", password="pswd")
for name, value in defaultMessages.items():
verifyChatMessages(**{name:value})
verifyChatMessages(shouldFail=True, **{name:"New Message"})
editChatMessages(**{name:"New Message"})
verifyChatMessages(**{name:"New Message"})
verifyMessages(shouldFail=True, **{name:value})
editChatMessages(**{name:value})
verifyChatMessage(**{name:value})
logoutTraderTask(trader="Trader1")
This is a substantial improvement from the XML test. First of all, the Jython version reduces errors in test writing while making it easier to read, since the loop clearly indicates that the same set of functions is being performed. It is also easier to maintain the Jython test, since a change in the loop changes the execution of each of the five tests. Additionally, the default messages are abstracted again, reducing errors and increasing readability and maintainability.
User Interface Scripting
With the J2SE 1.4 release you can use the java.beans.XMLEncoder and java.beans.XMLDecoder classes to persist Swing components using XML. There are other XML-based projects that go further. The JellySwing project found on the Apache Jakarta Project site uses scripts encoded as XML documents to define Swing front ends for your applications. This allows you to minimize the code required to build Swing UIs by as much as 30% or more. Additionally, the use of XML rather than Java Swing code allows for such XML techniques as XSL transforms to generate UIs. But JellySwing isn't good at everything, particularly when the language boundary is crossed. We have just seen the benefits of replacing XML-based scripting with Jython. Now we'll take a look at which JellySwing tasks might be better accomplished with a scripting language such as Jython.
In JellySwing, the Swing user interfaces are specified in XML, and a controller interprets the description at runtime and builds the screens. The following example depicts a basic Swing UI with a JMenuBar and three JButtons, each printing a message to the log.
<?xml version="1.0"?>
<j:jelly
xmlns:j="jelly:core"
xmlns="jelly:swing"
xmlns:log="jelly:log"
xmlns:define="jelly:define">
<define:script var="onClosing">
<log:info>The frame is closing via event: ${event}</log:info>
</define:script>
<frame title="This is a frame" var="frame" location="100,100" size="800,400">
<menuBar>
<menu text="File">
<menuItem>
<action name="New">
<log:info>clicked on the New menu item!</log:info>
</action>
</menuItem>
<menuItem>
<action name="Open">
<log:info>Popup a file dialog!</log:info>
</action>
</menuItem>
<separator/>
<menuItem text="Save" enabled="false" />
</menu>
</menuBar>
<panel>
<titledBorder title="Sample Border Title"/>
<tableLayout>
<tr>
<td>
<button>
<action name="Button One">
<log:info>Clicked on Button One</log:info>
</action>
</button>
</td>
<td>
<button>
<action name="Button Two">
<log:info>Clicked on Button Two</log:info>
</action>
</button>
</td>
<td>
<button>
<action name="Button Three">
<log:info>Clicked on Button three</log:info>
</action>
</button>
</td>
</tr>
</tableLayout>
</panel>
<windowListener var="event" closing="${onClosing}"/>
</frame>
${frame.show()}
</j:jelly>
You may not notice this immediately, but the JellySwing XML is approximately 40 lines shorter then the comparable Java Swing code; already a huge benefit. So let's take a closer look at the code. You can classify the JellySwing XML in three basic categories; most of the example is declarative, with several components added, attributes set, values declared, and layouts configured. This is much like the code that would be generated by XMLEncoder. Here is an example of this declarative type of code.
<menuItem text="Save" enabled="false" />
The script also contains embedded Java code. As an example, the next-to-last line in the script is a method call to the show() method of the frame just constructed.
${frame.show()}
Finally, you can identify instances of event handling like the following, which attaches a WindowListener to the JFrame and logs a message:
<define:script var="onClosing">
<log:info>The frame is closing via event: ${event}</log:info>
</define:script>
This attaches a window-closing listener that logs a message when the window is closing, including the event. Here is a different example that not only prints text information, but also retrieves values from the other components, like the TextField text:
<toolBar style="vertical">
<toolItem text="Click Me" toolTipText="I am a ToolBar you can click">
<onEvent type="Selection">
<log:info>Clicked event ${event} and TF contains ${textField.text}</log:info>
</onEvent>
</toolItem>
</toolbar>
In many ways, this feels a lot like embedding Java code in JSPs; this is Java code embedded in XML. Although these two event-handling examples are fairly tame, this injection of Java code occurs throughout JellySwing XML. The following example, taken from an example on the JellySwing web site, includes a large percentage of Java code used to set table values:
Although the example states that this would be implemented differently, it clearly shows a fundamental problem with JellySwing. XML is being used as a programming language. Essentially, Java code is embedded in XML. This can cause several problems in development. Code writing is more difficult without development tools like code completion and introspection. Debugging is also impossible, since an IDE debugger can't debug this embedded Java.
To avoid embedding Java code in XML, let's look how this could be implemented in Jython. The following is a port of the JellySwing XML to Jython:
from javax.swing import *
#from java.awt.event import *
from java.awt import *
from java.lang import *
win = JFrame("This is a frame")
win.bounds = 100,100,100,100
win.defaultCloseOperation = 3 #EXIT_ON_CLOSE
menuBar = JMenuBar()
fileMenu = JMenu("File")
menuBar.add(fileMenu);
newMenuItem = JMenuItem("New")
newMenuItem.actionPerformed=lambda event : System.out.println("Clicked on New Menu Item")
fileMenu.add(newMenuItem)
openMenuItem = JMenuItem("Open")
openMenuItem.actionPerformed=lambda event : System.out.println("Clicked on Open Menu Item")
fileMenu.add(openMenuItem)
saveMenuItem = JMenuItem("Save")
saveMenuItem.actionPerformed=lambda event : System.out.println("Clicked on Save Menu Item")
fileMenu.add(saveMenuItem)
saveMenuItem.enabled = 0 #false
win.JMenuBar = menuBar
contentPane = win.contentPane
contentPane.layout = GridLayout()
buttonOne = JButton("Button One")
buttonOne.actionPerformed=lambda event : System.out.println("Clicked on Button One")
contentPane.add(buttonOne)
buttonTwo = JButton("Button Two")
buttonTwo.actionPerformed=lambda event : System.out.println("Clicked on Button Two")
contentPane.add(buttonTwo)
buttonThree = JButton("Button Three")
buttonThree.actionPerformed=lambda event : System.out.println("Clicked on Button Three")
contentPane.add(buttonThree)
win.pack()
win.show()
Again the Jython code is even more compact than the JellySwing XML. In fact, the Jython version is approximately 20 lines less than the comparable JellySwing version, and 60 lines shorter than the JavaSwing code. Additionally, it is more readable by Java programmers, since Jython syntax is closer to regular Java. Plus, we get the benefit of language interoperability. We can write the user interface code in Jython and the event code in Java, we could implement all of the event code and UI code in Jython, and most importantly, we can refactor the code between Jython and Java as our project grows. Jelly and tools like it may be appropriate tools for the declarative portions of specifying a Swing GUI, but fall short once real code is introduced into the XML.
ANT
ANT is a great tool. Unifying build and package commands into a file easily read and distributed in XML has been a great help to all sorts of projects. But the XML representation in ANT has become a scripting language in and of itself. The ANT syntax may be so familiar that you no longer remember your first experiences with complex build scripts. Even the use of the term "build script" is an indication of the possible inappropriate use of XML in this setting.
There is a visible struggle in the use of XML as a programming language in ANT. Note that properties are used in ANT scripts. We saw the problems with introducing variables into XML in our first example. In ANT, the result is that properties are represented in the form ${PROPERTY }. This causes confusion with many ANT developers. For example, you can't change a property once its been set, because it is a property, not a variable. This is exactly the kind of trouble you run into trying to make XML work as a programming language. To further illustrate the point, here is an example using ANT's native conditional task:
<condition property="failmessage" value="Files up to date - build not required">
<and>
<isset property="build.notRequired"/>
<not>
<isset property="sync.external"/>
</not>
</and>
</condition>
This sample sets the failmessage property to Files up to date - build not required only if build.notrequired is set and sync.external is not set. In my mind, this is completely illegible. This task is going over the edge implementing conditional functionality in XML, clearly crossing the boundary from XML markup syntax to a programming language.
The ANT community continues to push ANT further in the direction of a custom scripting language. Since ANT was developed, there have been plugins created for implementing conditionals, loops, and other programming constructs in ANT XML syntax. With these techniques, they have created a programming language in XML! The following is an example taken from the ant-contrib Sourceforge project implementing try/catch functionality in ANT XML:
It might be nice to use these conditionals, loops, and variables in ANT without "programming" in XML. If these complex build scripts need to be written, then what we really need is a scripting-language-based ANT, not ANT plugins. An ANT that uses Jython, for example, instead of XML. Then we would have the power of an entire programming language at our fingertips, with all of the developing and debugging tools that go with it. Here is an example of what the previous conditional example might look like in Jython.
if (buildNotRequired && !syncExternal())
failmessage = "Files up to date - build not reqired"
Here is another basic ANT task better represented in Jython. This example shows the use of an ANT fileset to sign all of the .jar files in a directory.
This same procedure can be written much more legibly in Jython:
for jarFile in getFiles(jarDir, "*.jar" exclude="jnet.jar")
signJar(jarFile, keystore, alias, keypass)
Not only is this easier to write and understand than the XML, but it comes for free -- it's just Jython. We didn't have to implement specific functionality to get this to work; it's simply part of the language. And someone else is maintaining the language, testing it, and releasing it. By contrast, each function that supports filesets in ANT has to be specifically implemented.
Stay Tuned
Next time, I will show you how to implement real working ANT scripts directly in Jython. All of the ANT tasks have underlying Java code that can be called directly from Jython without any "glue." This is because Jython runs in Java and can communicate directly with any Java code. This includes calling the underlying Java-based ANT code in addition to the Java code supporting any ANT plugin. This is really a great example showing the power of a Java-based scripting language.
Conclusion
My bias is that XML is a great tool that is misapplied when it is used as a programming language. You have seen a few examples where the XML markup/programming language boundary has been crossed, and where a scripting language like Jython may be a better alternative. Jython is easier to read and write compared to XML, because of its similar syntax to Java code. Additionally, Jython can communicate with all of your other Java code. So the only real difference between Java code and Jython is syntax, rather than the complete incompatibility between Java and XML.
There is also some hesitation in moving from XML to scripting languages partly because of perceived limits in portability. A build script written in Jython must be rewritten to work in JRuby. If we switch from ANT to another tool, we can always write an interpreter that allows us to continue to use the existing XML scripts with our new tool. This is also a hesitation of developers to use Java scripting languages, since they are arguably less mature then Java and XML and have fewer development tools. But maybe, if we as a community begin to get vocal about when a Java scripting languages should be used, the open source community and our vendors will develop better and stronger tools to support Java scripting languages.
Resources
I wanted to thank the Developers and QA at Liquidnet, as well as the SWT listserv, for ideas and information on Java scripting.
is another java scripting language to consider. Like jython, it can extend java classes (and implement java interfaces), which is handly for creating a swing UI. But it is much faster than jython, and has a syntax that would perhaps be more familiar to a java developer.
There is already a Phython based replacement to ant or make called SCons.
http://www.scons.org/
It looks very good, indeed!
User Interface Scripting
2003-06-24 03:20:54 machicoane
[Reply | View]
Jonathan,
Sorry but, even though I'm a Jython fan, I don't fully agree with your opinion regarding the suitability of XML as a User Interface Scripting language. JellySwing is one implementation among others of this approach. I definitely think that XML can be perfect for UI definition provided that :
Business logic is clearly separated from the UI stuff (which is not the case with JellySwing).
Because XML is especially wordy, the UI must not be specified in plain XML, but throuh an user friendly IDE (e.g. XML editor).
From these points, I've developed SMaWL which implements the concepts here above and greatly speeds up UI design.
Cheers. Thierry.
I would ask why not JavaScript
2003-06-23 23:46:44 btal
[Reply | View]
I would suggest using JavaScript.
1. It is a valid scripting language.
2. Its most close to the Java language in syntax.
3. It is "more readable" than Jython (in my opinion).
Jython instad of Ant
2003-06-18 08:32:42 mdhirsch
[Reply | View]
I like the idea of using jython instead of ant for build scripts. Ant is too clumsy, and missing too many scripty things (like conditionals and iterators).
On the other hand, I like that ant makes it easy to set up dependencies between targets. Using jysthin, it sems like I'd have to actually code in the dependencies into each method. Maybe we could write a jython/ant hybrid system.
Jython instad of Ant
2003-09-11 10:52:51 ghouston
[Reply | View]
Yes, I like the idea of using a real language to script builds. Too many times I've hit problems I couldn't accomplish in Ant.
Has anyone had experience calling Ant tasks from Jython? If it is easy to call Ant tasks, then it would be easy to convert existing build.xml files Jython. Providing a good migration path from Ant to Jython is needed.
Jython instad of Ant
2003-12-09 01:36:43 tjeerd_verhagen
[Reply | View]
Why not call a Jython script from within Ant. It's easily done through the Bean Scripting Framework.
http://jakarta.apache.org/bsf/
Python as a scripting language
2003-06-18 03:19:40 tremolo
[Reply | View]
If you want a full featured python support for building try SCons it is completely based on python and offers some nice possibilities. I use it for some time now.
It's easy to use, and very powerful.
http://www.scons.org
The Jython/Ant-approach is also very interesting though.
Python as a scripting language
2003-06-23 06:12:08 stevenknight
[Reply | View]
SCons has recently added support for compiling Java (javac, javah, jar and rmic), including good dependency analysis involving MD5 signatures of source file contents and a stripped-down parser that figures out what .class files will be generated. We're also adding support for more and more Ant tasks, although because Scons is in Python, not Jython, these are Python re-implementations, not calls to Ant's Java implementations.
One SCons goal has always been to make it completely portable to Jython. We've generalized some small things to make it more Jython-friendly, but haven't yet had a Jython expert on board who can really complete the support appropriately. If anyone is interested, please contact us through the SCons web site (URL in tremolo's post, above).
If you want a nice scripting language, you might want to consider using Java. BeanShell (www.beanshell.org) is Java as a scripting language. It integrates seamlessly with existing Java code and even Ant through the use of BSF.
We use it in Out-of-the-Box (distribution of 100+ Open Source projects for Java developers) when we need a little extra boost of power in our Ant scripts.
Why not Tcl?
2003-06-17 08:23:10 joncruz
[Reply | View]
Why not use Tcl for the scripting? Pure Java implementations such as Jacl are available. http://www.tcl.tk/software/java/
For many situations Tcl might be a good option, given that it was created for scripting applications, is a little simpler than python, QA/other developers might already know it, etc.
Why not Tcl?
2003-06-17 09:27:14 jonathansimon
[Reply | View]
No reason not to use Jacl. The point of this article was to enlighten folks to the benefits of scripting. Jython is just an example. There is also Jacl as you mentioned, JRuby, Bean Scripting Framework (BSF) and other.
Look here for a partial list: http://wiki.java.net/bin/view/Javapedia/JavaScripting
Why not Tcl?
2003-06-18 01:38:58 sruchet
[Reply | View]
We used jacl before jython. The great advantage of jython is that we can easily override java classes and/or interfaces; that is not easy to do that with jacl.
Another point is, IMHO, jython is more readable.
Why not Java instead of Jython instead of XML?
2003-06-14 01:28:06 goopot
[Reply | View]
I may be missing something, but why not use Java as the language to set up and run your tests?
If you used Junit then perhaps the " testing infrastructure that my company is developing" would turn out to be a re-invention of the wheel?
Why not Java instead of Jython instead of XML?
2003-06-16 14:04:39 jonathansimon
[Reply | View]
Because Java is not a scripting language. True you could do it in Java, but then you have to worry about static typing and generally a much more complex syntax. The idea is to use Jython when Java is too heavyweight. Then you end up putting in an upfront commitment to incorporate Jython, but reap the benefits when your task can be accomplished quickly with a scripting language.
Why not Java instead of Jython instead of XML?
2003-06-18 08:51:43 c_armstrong
[Reply | View]
I like static typing. With static typing the compiler finds your bugs before your users do.
Why not Java instead of Jython instead of XML?
2003-06-18 09:10:35 jonathansimon
[Reply | View]
Check out this blog discussion of static typing and testing...
http://www.mindview.net/WebLog/log-0025
Why not Java instead of Jython instead of XML?
2003-06-18 09:48:01 c_armstrong
[Reply | View]
I forgot to say - I do thoroughly agree with your main point though. XML IS NOT A PROGRAMMING LANGUAGE ought to be one of the ten commandments of computing as its a fallacy I see so often....
Why not Java instead of Jython instead of XML?
2003-06-18 09:44:37 c_armstrong
[Reply | View]
An interesting read for sure...
However: When I was studying academics used to insist I used IMPLICIT NONE in Fortran programs. I never had any problems caused by lack of it, so thought they were being pedantic. Then a few years later I saw an outage resulting in $40,000 worth of outage clauses caused by the lack of an IMPLICIT NONE.... So I guess it depends on whether something is for personal use or mission critical - but for me static type checking is a vital wall of defence against scenarios I don't forsee or test for...
Why not Java instead of Jython instead of XML?
2003-06-16 14:37:54 goopot
[Reply | View]
I buy the complexity argument if you are working by yourself and already know python and java. In a team environment where it is likely that everyone knows java but not everyone knows python, the the easiest solution taken as a whole must be for a single language do you not think?
Why not Java instead of Jython instead of XML?
2003-08-22 06:18:36 cupdike
[Reply | View]
That may be the easy solution, but I don't think it is the best solution. I think anyone that knows java should learn jython because it will make you a better/faster developer. When I have to develop something new in java, I usually prototype the algorithm using jython. It's just so much faster and easier to skip the compile/debug/run cycle. Running from a command line lets you incrementally build gui's and play with them in ways that would be too tedious in java. Same thing for io, string parsing, code generation (especially generating test cases), bit manipulation, math, etc., etc. Then when I write the java code, I know what I'm trying to write. I don't "explore" in java, only in jython.
Why not Java instead of Jython instead of XML?
2003-06-18 01:37:04 sruchet
[Reply | View]
Jython is really easy to learn. Knowing Java and jython is not a problem because they are very similar. Note that you must know java for scripting in jython.
Really, writing test scripts in jython is a pure pleasure, because it is very legible, quick to write, and easy to maintain.
I'm tooting my own horn here... my open-source test tool TestMaker has been using Jython as an embedded scripting engine for the past year. The TestMaker community (now 38,000 strong) has been using Jython to script tests like this and it's worked out great.
One thing I wish the article showed is that with the right environment, running the Jython-based test scripts multiple times and concurrently is an easy way to do scalability and performance (load) testing.
Details on TestMaker are at http://www.pushtotest.com/ptt
It strikes me that your comments about using XML as a scripting language could equally apply to the development of "scripting JSP tags" such as the logic tags in Struts.
The intermingling of logic with declarative statements seems to be unavoidable, but the approach of many tag writers concerns me. Why develop a tag based scripting language rather then using a "real" scripting language?
or defining your own classes.
{define-class InfoView {inherits View}
{constructor {default ...} {construct-super ...}}
{method public {destroy}:void {self.hide}}
}
Anyone play with "Curl"
2003-06-11 17:12:49 jonathansimon
[Reply | View]
Allright... I just replied to the wrong reply and I cant fix it. Check out below.
I can definately see this is an improvement over vanilla XML, but I still think its less clean than other scripting languages like Jython and JRuby.
For Java projects, using something like Jython is great because its like writing Java pseudo-code that actually runs. This syntax is quite different.
Thanks for the info though. I'll see if I can think of some places where this might be useful.
JellySwing, structure and logic
2003-06-10 12:07:17 mikesego
[Reply | View]
I agree that the logic should avoided in JellySwing (and JellySWT) just as it should be avoided in JSP. However, I prefer the hierarchical structure of XML for declaring UI's to code in Java or Jython. It's easier to read because with code, you have to follow variable names which ultimately build a nested hierarchy which is naturally expressed in XML.
I haven't worked with JellySwing, but I think it would be preferable for onevent to reference event code externally defined in Java/Jython, rather than writing the code in Jelly script.