Java is great, but it has a reputation for being a bit verbose and requiring a decent amount of ‘scaffolding’ code to be able to do fairly simple things. It’s also a skill set that a lot of people come out of school with. So how do we take a common skill set and leverage it to build things faster? Well that’s where groovy comes in.

Groovy takes everything from Java, and adds a level of dynamicism that can’t be found in Java. Functional concepts like closures were added to Groovy before Java adopted the concept of lambda functions. Although all Java syntax is supported by groovy, a lot of it is also not needed. Like the dreaded missing semi-colon. we’re nearly a quarter century into the new millennium, do we really need an extra character when the line break does the job of telling where code ends? A more flexible syntax also makes it much easier to apply different types of ‘syntactic sugar’ in specific areas.

One example of this that I’ve had the pleasure of working with is with Jenkins pipeline files and libraries. By defining a specification for all the different types of functions you expect to find in a script, you can build easy to read and extensible frameworks. I have also got to work with Groovy and the Spock testing framework to define beautifully simple test specs. The use of declarative blocks to define stages of your test script and applying abstract syntax tree transformation to do things like automatically assert conditions in specific areas of your test reduces a lot of the cognitive complexity of writing code so that more time can be spent focusing on business logic.

On top of all of these improvements, Groovy can also run as a script as opposed to a full blown application. While this has a bit of a negative impact on startup times, it can be very handy to generate dynamic scripts in places like build pipelines, docker containers, and the like to provide simple functionality. If java is an 18 volt drill with adjustable torque and impact driver setting, Groovy is a little electric screwdriver that fits all the same drill bits. Sure, sometimes you’re going to need that impact setting, but most of the time, the screw driver is going to do the trick and take up a lot less space in your pocket.