Interesting stuff. Todd, please say a few more words on why Jython is not "scripting".
For me, scripting has the following values:
- Brevity (Succinctness) - Being able to do coarse grain things (i.e. delete files, remove directories, transfer data, manipulate the "general purpose" language in very little code.
- Language Constructs Geared Toward Control - If you are scripting a "general purpose" language (C, Java, etc), the scripting language should be syntatically and semantically simpler. It shouldn't fight with the language its scripting. You want to control the general purpose language's objects and artifacts, not perform a mind meld with it. You want to sling objects, not perform brain surgery on them.
- Rapid Prototyping - I should be able to write scripts rapidly (but still safely!).
- Brevity - Jython has some syntax shortcuts (array slicing, dictionaries, tuples, etc) but Python was never very succinct to begin with. This is not a criticism. Python was meant to be read, not scanned. Even its List Comprehensions are verbose compared to, say, Haskell. I find myself slinging classes quite a bit in Python. And that's not much briefer than Java.
- Language Constructs - Jython has its own rules. Data type conversion between Java and Jython is a subtle thing. Both Java and Python have distinct concepts attached to data typing. Same said for classes (and introspection on those classes). Who conforms to whom? Is Java the master and Jython the slave? Should programming Jython feel like Python or Java?
- Okay, this gets biased. Its similiar to item #1, but is more about how quickly I can do things with what I have. It's best represented by solving the following real problem: I have a test suite that generates a subdirectory and a bunch of files. How do I delete the files and subdirectory when I am done?
import os os.chdir(dir) for f in os.listdir(dir): os.remove(f) os.chdir('..') os.rmdir(dir)(NEM: do you really need to change the working directory to do this in Python?)Jython:
import os os.chdir(dir)Oops! The os file functions aren't available in Jython... We need to go to Java for this:Jython (again):
from java.io import File for f in File(dir).listFiles(): File(str(f)).delete() # Notice str(f) is needed: Java types vs Python... File(dir).delete()Tcl:
file delete -force $dirJacl:
file delete -force $dir-- Todd Coramsnichols Interesting examples. I consider Jython to be a scripting language because it supports duck typing and you can program on the fly using Jython's interpreter. In our office there is a debate going on whether to continue to use Jython or use BeanShell instead for our functional tests. One advantage BeanShell provides for the Java developer is that they really don't need to learn a new language because BeanShell looks just like Java except it supports duck typing, which is a good thing. Duck typing is where you don't have to declare the variable first. You simply can start using it and change its type on the fly. I think all scripting languages have this.-- RLHWell "scripting" has been replaced with "dynamic" now. So you basically have either a "static" or a "dynamic" language. Oh and Jython is at 2.2 now.