Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Groovy for Domain-Specific Languages, Second Edition

You're reading from  Groovy for Domain-Specific Languages, Second Edition

Product type Book
Published in Sep 2015
Publisher
ISBN-13 9781849695404
Pages 386 pages
Edition 1st Edition
Languages
Author (1):
Fergal Dearle Fergal Dearle
Profile icon Fergal Dearle

Table of Contents (20) Chapters

Groovy for Domain-specific Languages Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
1. Introduction to DSLs and Groovy 2. Groovy Quick Start 3. Essential Groovy DSLs 4. The Groovy Language 5. Groovy Closures 6. Example DSL – GeeTwitter 7. Power Groovy DSL Features 8. AST Transformations 9. Existing Groovy DSLs 10. Building a Builder 11. Implementing a Rules DSL 12. Integrating It All Index

Chapter 1. Introduction to DSLs and Groovy

It has been over 10 years since my first contact with the Groovy language. The occasion was an introductory talk about Groovy at JavaOne in the Moscone Centre, San Francisco, by James Strachan, the creator of the Groovy language. Java itself was just 10 years old at that time and Groovy was one of the very first languages other than Java to run on the Java Virtual Machine (JVM).

Just this year, Java celebrated its twentieth birthday. In 2005, there were an estimated 3 million Java developers worldwide. Now, in 2015, Wikipedia estimates it as 11 million. The Groovy language has also taken off. There were an estimated 5 million downloads of Groovy in the last year alone. So what are the benefits of Groovy and why should you consider using it?

The Groovy project site at http://www.groovy-lang.org explains this better than I ever could with six major benefits:

  • A flat learning curve

  • Powerful features

  • Smooth Java integration

  • Domain-specific languages

  • A vibrant and rich ecosystem

  • The scripting and testing glue

In this book, we will cover all the key benefits of the Groovy language. The main focus, however, is on how Groovy supports the development of domain-specific languages through its metaprogramming features.

One of the big benefits of Groovy is how its dynamic features support the development of domain-specific languages (DSLs) or "mini languages", which we can run directly on the JVM alongside your existing Java code. Groovy DSLs integrate seamlessly into the Groovy language itself in such a way that it's not always apparent where the regular Groovy code stops and the DSL starts.

In fact, large parts of almost any Groovy application are written using Groovy-based DSLs. For instance, a new developer starting out with Groovy might assume that the builder code he uses to output some XML is a part of the core Groovy language. But it is, in fact, a mini internal DSL implemented using the Groovy metaprogramming features.

If you are an Android developer, the chances are you may have programmed in Groovy already. Since 2013, the build system in the Android SDK has been a tool called Gradle (http://www.gradle.org). Gradle is a Groovy-based DSL for dependency management and build automation.

Whether you are one of the 11 million existing Java developers, looking to add DSL features to you application, or you are an existing Groovy developer looking to improve your knowledge of DSL writing, metaobject programming or AST transformations, this book is intended for you.

By the end of this book, I hope that you will have the knowledge and the confidence to start building your own DSLs with Groovy, and be able to integrate them into your Java applications. To begin with, in this chapter, we will take some baby steps. This chapter will give you a brief background on DSLs and their usage. We will also dip a toe into the Groovy language, and briefly touch on the features of the language that distinguish it from Java and make it a great tool for developing DSLs on top of the Java platform.

You have been reading a chapter from
Groovy for Domain-Specific Languages, Second Edition
Published in: Sep 2015 Publisher: ISBN-13: 9781849695404
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}