 |
Java and scripts and pipes
Posted by johnreynolds on March 24, 2005 at 08:16 AM | Comments (4)
All the recent ramblings about Groovy and Jython makes me wonder:
What makes scripting so powerful?
Let's start with what a "script" is:
In a play a script tells the actors what to do. In a software environment a script tells preexisting components what to do.
Scripts aren't about creating actors or components, they're about orchestrating actors or components.
So why isn't Java a scripting language? After all, Java can be used to invoke preexisting components.
I think that shells and pipes are the answer. Scripting languages (such as bash) have interactive shells. The shell lets an author interactively develop and execute the scripted behavior of preexisting actors (components)... but it also places constraints on those components to enable the use of pipes.
Components that can be executed within a shell must have well defined text-based interfaces. Each component must be able to accept text-based input, and each component must return a text-based outcome. If non-text input or output parameters are necessary, they must be packaged in entities that can be referenced by a text string (such as a file or a stream). These interface constraints are what enables pipes, and the ability to pipe the outcome of one component to another is a big factor in what makes shell scripts so powerful.
I'm just thinking out loud here, but when I look at Groovy and Jython and compare them to bash, I get worried that the value of scripts and pipes might get lost in all the syntactic sugar.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Hi John,
It's easy enough to put together a class that reads text from standard input, so I don't think there's really a technical hurdle preventing Java from being used for pipes. Java's built-in regex support makes this kind of processing simple, and the extensive libraries available for Java can make some fairly amazing tools possible with minimal effort.
In my (biased - you'll see why in a moment) opinion, it's the startup overhead associated with the JVM that prevents Java from being used as a general-purpose scripting language. Beanshell (http://www.beanshell.org) has been around even longer than groovy and jython (I believe), and yet is not to my knowledge widely used as a general command-line scripting tool.
I have a project called NailGun (http://www.martiansoftware.com/nailgun - hence my bias) that attempts to address the JVM startup issue by running everything in a persistent JVM. It makes small utilities and "hit & run" style Java programs tolerable - even fast - and I can't think of any reason a developer familiar with jython, groovy, or beanshell couldn't have NailGun running their scripts in under a lunchbreak. You or your readers might find it useful in tinkering with java-as-scripting-language. It's available under an Apache-style license.
- Marty
Posted by: martylamb on March 24, 2005 at 10:31 AM
-
I agree with you Marty... it's not so much a technical hurdle as a mind-set shift.
NailGun sounds interesting, I'll definitely check it out.
Posted by: johnreynolds on March 24, 2005 at 11:12 AM
-
Scripts are great for dynamic systems and even used in combination with compiled ones. The problem you have is that you can never even guarantee a scripted language will even run. That's even a problem I see w/ struts or other frameworks. There's never a end-to-end validation that everythign from the jsp page to a database table will work together in harmony.
Posted by: smartinumcp on March 25, 2005 at 06:30 AM
-
Yes you are absolutely right in that the script is about orchestrating underlying components and not about creating actors/components.
In fact Java in a way is indeed a scripting language for the operating systems as much as SQL for databases and Perl for Unix C.
It's about the flavour of script or for that matter the 'drama' for which the script is written that decides which 'scripting language' to use!
Also scripting has its own usage domain, we need to ask what is the purpose? - is it how to make 'writing a program' as easier as possible to a general programmer or - giving a 'language grammer' to an expert to write almost 'any program'.
So it boils down to - how you want to program rather than the question 'why Java cannot be used as scripting language'.
Then it is indeed all about 'syntactic sugar' :-)
Posted by: vijayphadke on March 25, 2005 at 11:19 AM
|