Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Groovy expel Beanshell at my job?

 
Seth Dustin
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Swierczek
Ranch Hand
Posts: 125
1
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic