3. “Using a computer requires a fair amount of
ritual and ceremony…The less you interact
with your computer, the faster you can go.
In other words, eliminating ceremony allows
you to get to the essence of the problem.”
Neal Ford – The Productive Programmer
Welcome!I am Chris, and we’re talking about Groovy * Wrote a groovy coral service * Wrote GroovyTrailsMy Goals * Not to cover all aspects of Groovy * Not to convince you to port all of our code * Amuse bouche into the language * Convince you that it’s a good complement to Java
The paradox of productivity.
* You can incorporate groovy idioms as you ramp up.* You can cherry pick what parts you want
Groovy is incredibly easy to learn. * Very java-ish compared to other alternative languages. * My experience was that it took almost no time to learn. * Doesn’t require reading a book or learning a new paradigm.
* You can incorporate groovy idioms as you ramp up.* You can cherry pick what parts you want
Package protected is rarely used, but an annotation is available.Public and private are most common.
Package protected is rarely used, but an annotation is available.Public and private are most common.
Package protected is rarely used, but an annotation is available.Public and private are most common.
Great for one-off callbacks with frameworks (JdbcTemplates, PreparedStatementCreator, runnables, etc..)
So here’s what we started with – pretty vanilla java
And we’ve turned it into a trivial amount of code
Everything in java.util is imported by default, so you won’t accidentally include emory lists or something.
Everything in java.util is imported by default, so you won’t accidentally include emory lists or something.
You can use def for defining variables, meaning you don’t have to type class names twice.
Excluding return can clean up simple properties and calculations. For larger methods I find that it improves readability to leave them in.
Simplified collection construction, very nice!
Simplified collection construction, very nice!
Simplified collection construction, very nice!
Simplified collection construction, very nice!
Instead of calling setX, setY, we have a nice way of setting bean properties.Great for simple DI and test construction.
Each – you want to do something over every item in a list
INJECT!
This is what they’re actually called.Removes a lot of ugly code involving string concatenation with plusses, or String.format.
Feeds the next example
From actual service code.Converting from transport objects to a persisted domain modelPreviously had about 15 lines of anonymous class implementations calling different overloadsOne lambda to rule them all, dynamic multicastWhich is…
Defs become implicit.Better compile-time support, loss of dynamicismSpeed parity with Java for performance-sensitive codeAlso addsTraits