aspose file tools*
The moose likes Groovy and the fly likes Can Groovy expel Beanshell at my job? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Can Groovy expel Beanshell at my job?" Watch "Can Groovy expel Beanshell at my job?" New topic
Author

Can Groovy expel Beanshell at my job?

Seth Dustin
Greenhorn

Joined: Sep 15, 2010
Posts: 7
Ken,

Groovy sounds like a great extension of Java.

We've got beanshell as our defacto scripting environment at my place of work. Coincidentally, same as at my last place of work.

Can Groovy replace beanshell, and what arguments can I use to convince my boss to dump beanshell and go with Groovy?

thanks in advance,

Seth
Kenneth A. Kousen
gunslinger & author
Ranch Hand

Joined: Sep 18, 2002
Posts: 89
    
    5
One of Groovy's nicest features is that it can be used as a scripting language, though in practice most people write classes instead. Still, scripts are fine, and I cover both how to write them and how to test them in the book. If you give me a typical example of what you do in BeanShell I'll try to mock out a Groovy equivalent.

Groovy's best feature to management is its seamless integration with Java. You don't have to replace any existing Java code -- you can just add Groovy to it and it'll work. You don't lose any knowledge or existing libraries. You just add new power in about 1/10th as much easily readable code.

Incidentally, the Spring framework supports what they call "dynamic beans" in three languages: BeanShell, Ruby, and Groovy. I have a whole chapter on Spring and Groovy integration in the book.

By the way, my whole first chapter is an attempt to make the business case for adding Groovy to your system. I like to say it this way: Java is good for tools, libraries, and basic infrastructure. Groovy is good for everything else.


Kenneth A. Kousen, Ph.D. (assorted certs), President, Kousen IT, Inc.
Author of Making Java Groovy - http://www.kousenit.com
Michael Swierczek
Ranch Hand

Joined: Oct 07, 2005
Posts: 117
    
    1

This may be an unusual requirement, but one of the nice features of BeanShell is the "!= void" and "== void" checks, which you can use to check if a variable has or has not been previously defined. (This is of course separate from a regular null check, which checks whether a previously defined variable is null.)

Does Groovy offer something similar?

It's not a must-have, we can work around the absence with Groovy by switching from defining variables based on activity to putting the variable name and value into a Map, and then checking if the Map contains the corresponding key later.
Kenneth A. Kousen
gunslinger & author
Ranch Hand

Joined: Sep 18, 2002
Posts: 89
    
    5
I'm not aware of anything in Groovy that checks to see if a variable has been declared. Your proposed map-based solution ought to work, though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can Groovy expel Beanshell at my job?