Groovy

The Superb Homeless

Michał Mally / @michal_mally

Groovy Kind of Love

groove - a situation or an activity that one enjoys or to which one is especially well suited (found his groove playing bass in a trio). A very pleasurable experience; enjoy oneself (just sitting around, grooving on the music). To be affected with pleasurable excitement. To react or interact harmoniously.

Blue or red pill?

Evidences

Evidence #1: Gradle

Evidence #2: Geb

Evidence #3: Grails

Evidence #4: Spock Framework

Groovy...

  • truly dynamic language running on JVM
  • object-oriented (everything is an object) with functional traits
  • eventually compiled language... and scripting language
  • optionally typed language
  • optional static type checking and compilation
  • Java superset

Thesis

Groovy is an expressive, concise and JVM-based development-simplifying programming language. Groovy also provides seamless Java integration and flat learning curve for Java programmers.

Proof

(aka Groovy Propaganda)

Simpler Greeter

Java ~ 380 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 380 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 375 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 351 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 254 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 248 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 237 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 235 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 229 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 230 characters

Simpler Greeter

Java ~ 380 characters

Groovy ~ 230 characters

Assertions


Groovy Truth

assert "Groovy"

Truth is customizable!

GDK

73 enhanced types (incl primitives)

247 unique methods

1188 methods total

Strings

Regular expressions

Cool languages are Groovy and Java.

Ranges

[00000007VY, 00000007VZ, 00000007W0, 00000007W1]

Collections

[] + Ranges

Closures

more than Java 8 Lambdas

(but fully-compatible)

Java 8 Lambdas

Groovy Closures

Closures are first-class citizens

Calling closures

Birth context

Higher-order functions

Working with Closures

Calling Closures

Duck typing

If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck.
Groovy 2.4.1

Into world of DSL

Possible?

Metaprogramming

Writing code that writes code

Property missing

Possible?

Method missing

Possible?

10m ~ 11.84s

Intercept, Cache and Invoke

10m ~ 6.63s (44% faster)

JSON Builder

builder.toPrettyString()

Dynamic Builders

Dynamic Builders cont.

Abstract Syntax Tree

transform :: AST -> AST

Version example

@Lazy

@Memoized

Without @Memoized ~ 3m

With @Memoized ~ 5ms

@TailRecursive

GROOVY is for JAVIST

what

RUBY is for RUBYIST

michal@mally.pl

@michal_mally

Groovy would love your contribution!