Those dreaded words..'beanshell integration'

Oh how I shudder when I see that awful enhancement. Alas, it’s far too easy and alluring to succumb to this terrible infestation. You can barely move these days for all the bsh-1.2b7.jar files strewn about so carelessly and haphazardly.

What is so evil about beanshell, I hear the stupider readers inquire. Well, let me tell you. In very very few cases, it’s a perfectly legitimate API. It makes for a great teaching tool, and can be handy dandy for debugging and suchlike. However, as a core feature, it’s rubbish.

If you want a scripting language, then don’t use Java. Simple. if you enjoy severe lack of type safety and more dynamic binding that you can shake a stick at, don’t use Java. If you want to allow your users to inject random bits of code that do not adhere to any sort of contract in ways that man and God did not intend, then please, please, go take up Python and stop depositing your smelly turds over our language.

The problem is, those selfsame people who will allow you to embed beanshell scripts in xml files are those who will squeal like stuck pigs when confronted with a jsp scriptlet. Now I ask you, what is the difference? It’s a trick question, because there is NO DIFFERENCE. In both cases, you’re embedding code in a script. Believe it or not, the arguments for and against either technique are identical. You’re sacrificing compile time safety, you’re adding ugliness, mixing concerns. You’re gaining ease of development, lack of contracts, and ability to go crazy.

So, admit it. If you’re advocating beanshell, then you automatically lose all rights to bitch against code in jsp pages. Just because it’s an xml file does not mean its inherently superior or cooler, despite what 2001 told you.

8 Responses to “Those dreaded words..'beanshell integration'”

  1. Markus Kohler Says:

    You don’t need to put the shell scripts into an xml file. You can just put javascript code into a .js file.

    The advantage is that people who only know javascript (rhino) for example, will be able to extend/modify your application.

  2. Jason Carreira Says:

    I couldn’t agree with you more (for once)…

    There is one difference between scriptlets in a JSP and beanshell scripts in some XML file… At least with scriptlets you’re writing in the same language (Java) that you’re writing the rest of your system in…. With Beanshell you often end up with a mishmash of Java code stuck together with tons of duct-tape in python, perl, whatever-scripting-language-the-developer-throwing-in-todays-poorly-documented-feature-knows

  3. Christoph Sturm Says:

    I think you are mixing beanshell with the bean scripting framework, jason.

    and I think the main problem with jsp scriptlets is mixing style and code. Cant see how that would be the case with embedded scripts in an xml file (or in a database, or wherever)

    regards
    chris

  4. xod Says:

    Every day I hit this blog to read my unspoken thoughts passionately posted. I think we need the entertainment gossip field to experience a boom, or maybe a gold rush in interior decorating, so that all the label-whoring fad-following fashionistas will get the HELL out of coding and go do something more suited to their temperament. Their departure will leave behind those who greet new ideas with critical thought instead of slavish adoption of this week’s buzzword.

  5. Will Sargent Says:

    Beanshell is an interpreted language. JSP is a page compilation technology, wherein a template is compiled to a Java class.

    They are not the same thing, don’t work the same way, and don’t have the same performance characteristics.

    Moreover, the problem in embedding Java in JSP is in polluting the model with the presentation.

    In summary, I don’t see how disliking beanshell makes JSP scriptlets any more valid.

  6. Damien Bonvillain Says:

    I don’t see the point, Java scriplet in JSP are safe, you can compile them offline, a JSP is everything but dynamic.

  7. Brett Knights Says:

    In response to the original article:

    Actually I just finished adding BeanShell to the Saxon xslt engine for occasions when I need to spew xml into something other than a xml/html/text result. Works great.

  8. Stephan Bachofen Says:

    There are cases where beanshell makes sense.
    For an instance, it comes in pretty handy when you want to drive a java framework with a scripting language.

Leave a Reply