This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Jython/Python and the fly likes Embedded Scripting Languages: Success Stories? Jython? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Embedded Scripting Languages: Success Stories? Jython?" Watch "Embedded Scripting Languages: Success Stories? Jython?" New topic
Author

Embedded Scripting Languages: Success Stories? Jython?

Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
In my experience, embedded scripting is used broadly in two different ways
  • To add flexibility to an application or framework. The best known example is JavaScript embedded in web pages. Another good one is the use of elisp in the emacs editor.
  • To solve a problem in a language that is much more expressive in the problem domain. My favourite example is the use of an embedded XSLT processor to effect XML transformations; another example would be to use an embedded Prolog interpreter to formulate business rules in a business application framework.
  • The first type of embedded scripting can turn a good application into a great one; I'm sure the original authors of emacs had no idea what people would end up doing with it. The second type can easily improve productivity by an order of magnitude.
    Does anyone have particular success stories to share? And where does Jython fit in this spectrum?
    - Peter
    [ April 09, 2002: Message edited by: Peter den Haan ]
    Mapraputa Is
    Leverager of our synergies
    Sheriff

    Joined: Aug 26, 2000
    Posts: 10065
    To add flexibility to an application or framework. The best known example is JavaScript embedded in web pages. Another good one is the use of elisp in the emacs editor.
    Another example is Visual Basic for Applications with whose help you can call M$ Word's (for example) modules, record certain sequences of actions and thus automatize routine tasks. I always wanted to have this feature for my programs!
    Perhaps Jython will be "VBA" for Java world
    As far as I can imagine, this would require to specially design an applcation to be "scriptable". To make an application "configurable" we read properties/xml deployment descriptor/whatever else instead of using hard-coded logic. To make an application "scriptable" we probably should keep in mind that instead of one well-defined flow of control and track of calls, our methods can be called from anywhere and at any point.
    To solve a problem in a language that is much more expressive in the problem domain. My favourite example is the use of an embedded XSLT processor to effect XML transformations; another example would be to use an embedded Prolog interpreter to formulate business rules in a business application framework.
    Another benefit from embedded domain-specific languages is that they externalize logic, so changes to an application do not require recompiling, In case with XSLT it is often mentioned that presentation logic (HTML tags) is exported from Java code and can be esily adjusted.
    In case with business rules, ability for end user to change them according to fast-changing environment can be even more important than increased programmer's productivity.
    [ April 09, 2002: Message edited by: Mapraputa Is ]

    Uncontrolled vocabularies
    "I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
    Doug Wang
    Ranch Hand

    Joined: Oct 05, 2001
    Posts: 445
    Perhaps Jython will be "VBA" for Java world.
    I do like the idea. But Jython lacks Macro concept and maybe it just cant "record" actions in application currently. More work needed.
    [ April 09, 2002: Message edited by: Doug Wang ]

    Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep
    Karthik Guru
    Ranch Hand

    Joined: Mar 06, 2001
    Posts: 1209
    Now am able to appreciate your post.
    This probably stands out in the deluge of mails we have had uptil now!
    So according to you , you w'd'nt want to use (rather embed) a scripting language in your application unless it does somethign radically different in a radically different way.
    Good one!
    I think jython cannot achieve the same effect as what xslt does to our java application.
    It can only *simplify* your development process.
    One reason c'd be that python and Java are very similar languages by design(reference based, GC, similar set of good libraries)unlike say XSL and Java.
    Yeah python does support functional style of programming in addition to the usual style.
    I have no idea of prolog.
    I think the similarity in design + 100% pure java implementation probably prevents jython from helping you do things in an expressive manner??.
    So probably prolog helps you express extremely complicated things in a simple way?
    Slightly unrelated ..
    This happens to be one of the best presentations i have ever come across. There is a reference to what you have expressed. The author points out as to how Scheme has built in features to express our requirements in a neat manner.
    If you know lisp then this probabyl w'd'nt interest you much though! Anways..this the URL..
    Scheme Talk
    probably some day when we have JScheme, you w'd be interested in that. :-)
    I wish the author could pitch in here and clear the doubts!.
    Originally posted by Peter den Haan:
    In my experience, embedded scripting is used broadly in two different ways
  • To add flexibility to an application or framework. The best known example is JavaScript embedded in web pages. Another good one is the use of elisp in the emacs editor.
  • To solve a problem in a language that is much more expressive in the problem domain. My favourite example is the use of an embedded XSLT processor to effect XML transformations; another example would be to use an embedded Prolog interpreter to formulate business rules in a business application framework.
  • The first type of embedded scripting can turn a good application into a great one; I'm sure the original authors of emacs had no idea what people would end up doing with it. The second type can easily improve productivity by an order of magnitude.
    Does anyone have particular success stories to share? And where does Jython fit in this spectrum?
    - Peter
    [ April 09, 2002: Message edited by: Peter den Haan ]
    Karthik Guru
    Ranch Hand

    Joined: Mar 06, 2001
    Posts: 1209
    Check out the Thinking in Python Book from bruce eckel.
    Chapter 4:Fronting for an implementation
    has an excellent description of how to implement proxy pattern in Python.
    Quoting from the book...
    <quote>
    The beauty of using __getattr__( ) is that Proxy2 is completely generic, and not tied to any particular implementation (in Java, a rather complicated “dynamic proxy” has been invented to accomplish this same thing).
    </quote>
    i'm in awe of python since then :-)
    the language seems to be really neat and it feels good that i can seamlessly integrate it with java through jython.
    Burk Hufnagel
    Ranch Hand

    Joined: Oct 01, 2001
    Posts: 814
        
        3
    Karthik,
    If you really want to try something that has a "radically different way" you should check out Aspect Oriented Programming (look for AspectJ). It allows you to add features (called aspects) to your code that cuts across the object hierarchy.
    Probably the easiest example is when you want to add tracing code to find out what's going on in a system you've inherited. You tell AspectJ that before each method in your classes it should call a logging routine, then exec the code in the method, then hit the logging routine again. The AspectJ compiler then "weaves" into the classes you designate the code to do all that.
    I can't tell you much more since I just started looking at it, but it looks like a Very Powerful tool to me.
    Burk


    SCJP, SCJD, SCEA 5 "Any sufficiently analyzed magic is indistinguishable from science!" Agatha Heterodyne (Girl Genius)
    Peter den Haan
    author
    Ranch Hand

    Joined: Apr 20, 2000
    Posts: 3252
    Aspect orientation is a fascinating way to properly "orthogonalise" code concerns, much more so than you can do with inheritance. But it still seems to be poorly understood.
    - Peter
    Burk Hufnagel
    Ranch Hand

    Joined: Oct 01, 2001
    Posts: 814
        
        3
    True. I'm sure I don't truly "get" it yet either, but I just spotted an article in the May 2002 Software Development Magazine on using AOP for unit testing and it looks Very Interesting!
    There's a couple of AOP articles in this issue. If anyone out there is interested in AOP, SD has run articles in the past and this issue has an interview with Gregor Kiczales, the principal scientist working on it at Xerox PARC.
    Peter den Haan
    author
    Ranch Hand

    Joined: Apr 20, 2000
    Posts: 3252
    Originally posted by karthik Guru:
    So according to you , you w'd'nt want to use (rather embed) a scripting language in your application unless it does somethign radically different in a radically different way.
    Well, not necessarily. You may "just" want to get the agility and programmability that an embedded scripting language can give you (like emacs' elisp or Office's VBA). This can greatly improve the effectiveness and versatility of your application. The language needs to be relatively lightweight and high level; Jython appears to fit both criteria.
    But, yes, you may also want to use an embedded language for a completely different goal: because it is a much more expressive way to solve some of your problems. Like XSLT. One of the things I was wondering about is whether Jython has problem domains where it is an order of magnitude more effective than Java -- if it is anything like Perl, text manipulation might be one.
    I think jython cannot achieve the same effect as what xslt does to our java application. [...] I have no idea of prolog.
    In Prolog, you specify a set of constraints (knowledge) and rules and the interpreter uses these to work itself a way towards a solution (Experts please feel free to chip in; I'm getting out of my depth here). If the problem you're trying to solve involves rule inference, there's a chance that developing a solution in Prolog will be lots faster in both development and execution time.
    This highlights one property of such "order of magnitude more productivity" scripting languages: many of them represent a complete paradigm shift relative to a traditional programming language such as Java. XSLT is. Prolog is. On the other hand, Perl isn't.
    I think the similarity in design + 100% pure java implementation probably prevents jython from helping you do things in an expressive manner??.
    It's the design that counts, not the 100% pure Java implementation -- many XSLT processors are implemented in Java, that doesn't make them any less expressive.
    Thanks for the Scheme reference! There are actually a number of Scheme interpreters that run on the JVM; I don't have a clue how seaworthy they are.
    Another language-to-watch is Ruby; there's even a JRuby that also slots into the BeanScriptingFramework. Ruby is a very nice pure-OO language, in many ways similar to Python but evern more elegant and clean. Still a traditional programming language with all the pros and cons.
    - Peter
    [ April 10, 2002: Message edited by: Peter den Haan ]
    Mapraputa Is
    Leverager of our synergies
    Sheriff

    Joined: Aug 26, 2000
    Posts: 10065
    Originally posted by Peter den Haan:
    This highlights one property of such "order of magnitude more productivity" scripting languages: many of them represent a complete paradigm shift relative to a traditional programming language such as Java. XSLT is. Prolog is. On the other hand, Perl isn't.

    Ha, I was going to say it yesterday but didn't, because did not feel like an expert in "domain-specific languages" problem. But if you started this conversation... And I have an excuse that "domain-specific languages" is something I am really interested in.
    To sketch a mental framework: there are so-called "vertical domains" (accounting, electrical industry, medicine etc) and "horizontal domains" (XML transformation, various data-access languages, logging etc.) We are talking mostly about the last category, right? Then we can divide it into two categories again: languages that require a paradigm shift - because this is essentially why they are more productive, I would name SQL here with its shift toward declarative programming. Prolog also fits here. On the other hand, that XSLT is a functional language is an artifact. You named Perl, Jython should probably be placed here as well. These languages increase productivity the same way high-level languages increase it compared to assembler: by grouping chunks of job and allowing to call them by names. JSP tag libraries is another good example. With tag libraries you can design your own language and decide which functionality will be here and where to put it
    This brings us to another question. In my limited and very foreign experience, self-made languages exhibit particularly ugly syntax So it may be a really good thing to have some kind of language to define other languages. Success of XML in markup languages field demonstrates that such meta-languages may have a big potential. If there was some kind of "XML" to design your own domain-specific language, with lex and parser available and ready to use, it could cause a wave of new-born domain-specific languages (for better or worse )
    Mapraputa Is
    Leverager of our synergies
    Sheriff

    Joined: Aug 26, 2000
    Posts: 10065
    Originally posted by Mapraputa Is:
    If there was some kind of "XML" to design your own domain-specific language, with lex and parser available and ready to use, it could cause a wave of new-born domain-specific languages (for better or worse )

    There would be a superb tool for defining domain specific extensions, if M$ didn't cancel it's own "Intentional Programming" project. *This* was really superb project. "Generative Programming" (Czarnecki & Eisenecker) has the whole chapter devoted to Intentionall Programming. In this framework you can extend the language and add your own high-level abstractions. The language is represented as Abstract Syntax Tree and you have access to all methods defined on this tree, so you can change/add whatever you want, to add a few visual representation for your abstractions, for example. (i.e. to extend your language with both domain-specific abstractions and domain-specific notations). This gives us the right perspective: Abstract Syntax Tree is what matters, and both "source code" and "executable code" are artifacts.
    There isn't much about IP on the Internet, here is a nice collection of links http://www.omniscium.com/nerdy/ip/ and here a technical report by IP leader, Charles Simonyi, "The Death Of Computer Languages, The Birth of Intentional Programming" on ftp://ftp.research.microsoft.com/pub/TR/Tr-95-52.doc
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Embedded Scripting Languages: Success Stories? Jython?
     
    Similar Threads
    Jython ? what for ?
    java or javascript or jython
    Python/JPython, Ruby/JRudy, the point??
    The power of scripting languages
    This is for Mr Author--Bill