Groovy: Python on The JVM?
In 2004, a dynamically scripted version of Java was submitted and accepted to the JSR. This language was known as Groovy. It was soon adopted by Pivotal(makers of Spring and Spring-boot) and then moved under Apaches stewardship.
And while the language has had it’s up’s and downs, this year has seen it’s biggest growth within the past year; Groovy has been remained in the TOP 20 programming languages since January 2019 and is currently #14 passing Kotlin, Scala, Haskell and ALL OTHER Java variants to become the #2 JVM language… after Java!
What Makes Groovy So Popular?
The reason why Java is so UNPOPULAR with many Python, PHP, Javascript people is the verbosity and complexity. You will hear this over and over. I myself had issue with this as well.
But when Groovy came along, it removed that complexity and provided a clean path of adoption that was similar to other languages like Python or Ruby. For example the following are a side by side comparison of Ruby and Groovy collections:
And believe it or not, this is almost identical for python as well. There is virtually no difference, so the learning curve is next to ZERO.
Who is Adopting?
Groovy has seen huge adoption in the devops community in tools such as
… as a result you will see Groovy used nearly EVERYWHERE (whether people know it or not).
Groovy is also used heavily for development in places like:
- Netflix
- Target
- Disney
- Amazon
- Oracle
- Cisco
FUD: If it can’t statically compile, it can’t be as fast as JAVA
Wrong-a-mundo in so many ways. Groovy is VERY flexible. Because Groovy is 100% compatible with Java, you can write code dynamically OR statically.
In fact, Gradle recently put that to the test; in the Gradle 8.2, they converted their compiler to Kotlin (much to their detriment) and found out that the Kotlin static compiler was 3x slower
Groovy allows you to, write as statically as you want during development; this dramatically speeds up development time. Then once stable, @CompileStatic for Production. It’s that simple.
And you can even statically compile only portions of code if you want.
This gives you all the speed of JAVA that you need and want while at the same time getting the development speed of scripted languages!
FUD: JAVA is slow to develop in
Not Groovy. Since Groovy can be dynamically typed, this gives you EXTREMELY fast development times while at the same time allowing you to compile statically for extremely scalable speeds!
Want an example?
We tested with the spring-boot-starter-beapi plugin which has full security (JWT, CORS, RBAC&ABAC) using a machine with the following stats:
- 2.8ghz / 4 cores processor
- 1gb RAM
- localhost machine also running the MySQL DB/ehcache for the api service
It gets 5300/RPS under a load of 1000 concurrency and 6000 requests!!
Not enough? We tested against AWS Lambdas using a FREE TIER EC2 instance and AGAIN put EVERYTHING on the same instance (MySQL, ehcache, Tomcat and the api server). Guess what our benchmark looked like NOW? (Note: this is a cold start)
Thats right, we still get around 720/rps with FULL SECURITY and everything on ONE MACHINE!
And AWS Lambdas (for comparison) with NO SECURITY?
That API is jumping all over the place. Sometimes its 520/rps… sometimes its 420/rps. Its your gamble.
Overall
If you want …
- speed of development
- highly scalable application
- good community support
- stable language
Groovy has it and is now the second most widely supported Java language in existence!