Thinking back to January 2007 when the first edition of this book hit the shelves, feels
like time travel to the Middle Ages. The idea of using a programming language other
than Java on the Java platform was widely considered frivolous. Today, a new language
seems to pop up every other week, and we even go as far as designing languages for
specific domains (DSLs) on a per-project basis.
This evolution of languages reflects a change in concerns. If performance were
still our utmost concern, we would all be coding in a low-level language. But if performance
is considered “good enough” for our purposes, we now turn our focus on
human approachability.
Groovy has been a trendsetter for this development. Many Groovy features that
ease the burden of developers are now commonplace in novel languages and may
even find their way into newer versions of Java: literal declarations for common datatypes,
simplified property access, null-safe dereferencing, closures, and more. Surprisingly
many languages have adopted Groovy’s optional typing strategy—few languages
can claim to have static and dynamic behavior at the same time, though, the way Groovy
has since version 2.
Just like Groovy, the first edition of this book set some trends as well. The idea of having
every single listing as a self-testing piece of code resonated in the market and may be
one reason why the book is among Manning’s top-ten bestsellers of the decade.
Licensed to Mark Watson <nordickan@gmail.com>
The feedback for the first edition was overwhelming. We never expected to have so
many great developers speaking so nicely about our work. We have no words to express
this feeling of being proud and humbled at the same time. Most touching, though,
was the stranger who once gave Dierk a pat on the back and mumbled, “Thank you for
the book!” and then disappeared into the crowd. This book is for him.
We are fully aware that the first edition would have never been so successful if
Groovy itself had been less appealing. The reason for Groovy’s success is easy to see: it
delivers its power in the most Java-friendly manner. It is Java’s dynamic friend.
The development of Groovy, from version 1.0 covered in the first edition of this
book until the current version 2.4, has closed what used to be a syntax gap by providing
enums, annotations, generics, the classic for loop, nested classes, varargs,
static imports, and the ability to use Groovy closures where Java 8 expects lambda
expressions.
The Groovy project has progressed at a very high speed, not only in its core but
also at its periphery. We see, for example, new usages of compile-time metaprogramming.
This core feature gets instantly applied in the Spock testing framework,
which in turn contributes back its “power assert” feature to the core. The community
is buzzing and it has become a challenge to keep up to date with all the
developments and activities.
It’s only natural that many readers of the first edition of Groovy in Action (or “Gina”
as we say for short) demanded an update that we are now happy to deliver as the second
edition (codename “ReGina”). Our goal in this book is not only to rework the
code examples, update the API description, and explain new features, but also to reflect
the marketplace and the growth of the ecosystem. Groovy has evolved from a niche
language to the default choice for dynamic programming on the Java platform for
millions of developers.
Major financial organizations use Groovy to transfer billions of dollars every day,
space agencies watch the stars with the help of Groovy, and satellite live-data streams
are handled by Groovy code. Groovy is traveling the oceans, shipping containers
around the globe, helping software developers automate recurring tasks, and running
Mom’s website. We felt an obligation to provide an up-to-date, solid, and comprehensive
book to all these users.
Not only did Groovy and its environment change, we authors changed as well. We
enjoyed the luxury of working on Groovy projects, introducing new team members to
the language, running workshops and tutorials, recognizing struggles (and occasionally
struggling ourselves), finding lots of unanticipated use cases while consulting,
exploring new practices, using the toolset in anger, and generally facing the Groovy
development reality. The book reflects these experiences.
In this second edition, we put more emphasis on the optional typing system,
explain both dynamic and static metaprogramming in full depth, dive into type checking
and static compilation, cover domain-specific languages, and introduce new modules
that have evolved for user interfaces, testing, XML, JSON, database programing,
Licensed to Mark Watson <nordickan@gmail.com>
Web Services, dependency management, build automation, and concurrent programming
as well as give you an updated overview of the Groovy ecosystem. We hope you
will find this updated book an enjoyable and rewarding read.