Why Don't you Groovy?
Engineering Communities
05 May 2016
Orest Ivasiv
Software engineer, Softserve
Audience
Java developers
No experience in Groovy
Disclaimer
We will not talk about Groovy language in details
It's not a tutorial
We are not Groovy haters/lovers. We are pragmatic devs
Groovy is not a panacea, Groovy is a hammer
Hipsters are not Groovy (it's 2016)
Problems and Tasks
Java devs should not write scripts in Java
Bash, Python, Ruby, etc.
How to re-use existence Java knowledge in automation tasks
How to choose the right scripting language
How to automate on Windows, Linux and OSX
Why Java is bad for scripting and automation?
Tedious File and Network processing
Tedious collection processing
Tedious XML/JSON processing
Verbose type declaration
Limited DSL support
Painful object construction code
Just too verbose for small tasks
Slow Edit-Compile-Run loop
Scripts vs Tools
Scripts
Run on all major OSs
Easy to distribute
Easy to read and maintain
Reasonably small
Quick Edit-Run cycle
Performance is not important
E.g.
- Bash, Ruby, Python, Node.js, Groovy
- Tcl, Lua
Tools
No sources
"Fat" binary
Popular or/and minimal runtime
No runtime - single binary
Very easy to distribute
Low maintenance cost
E.g.
- Java/JVM, Go
- C/C++, Python, Node.js
Groovy
JVM language
Java, Scala, Clojure, Groovy, Kotlin
Superb interoperability with Java
Syntax is very similar to Java
All Java libraries can be used in Groovy
Almost all Java code is Groovy code
Groovy language is full of modern features
DSL
Groovy is compiled Language
Groovy is a dynamic language
Dynamic != interpreted
Interpreted == a runtime interprets an AST
Groovy compiles down to JVM bytecode
Language features
Language features
List
Map
GString
GDK
MOP
Builders
Groovy Samples
Launching a Jetty server to serve Groovy templates
@Grapes([
@Grab(group='org.eclipse.jetty.aggregate', module='jetty-server', version='8.1.7.v20120910'),
@Grab(group='org.eclipse.jetty.aggregate', module='jetty-servlet', version='8.1.7.v20120910'),
@Grab(group='javax.servlet', module='javax.servlet-api', version='3.0.1')])
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.*
import groovy.servlet.*
def runServer(duration) {
def server = new Server(8080)
def context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
context.resourceBase = "."
context.addServlet(TemplateServlet, "*.gsp")
server.start()
sleep duration
server.stop()
}
runServer(10000)
What's ugly in Groovy
JVM and Groovy script start time is slow
Limited OS-level scripting (see Python, Ruby)
Groovy is another language. It’s not Java (thanks cap)
Groovy is not well accepted in other communities
Not convenient to use Groovy without IDE
References
Who is Groovy? by Cédric Champeau – history and people behind Groovy language
(http://melix.github.io/blog/2015/02/who-is-groovy.html)
Blog about Groovy, Gradle and Grails(http://mrhaki.blogspot.com)
http://groovy-lang.org/(http://groovy-lang.org/)
Groovy on the Shell(https://www.youtube.com/watch?v=1ogwSsl6EGQ)
Curated list of awesome groovy libraries, frameworks and resourcesy(https://github.com/kdabir/awesome-
groovy)
Thank you
05 May 2016
Tags: groovy(#ZgotmplZ)
Orest Ivasiv
Software engineer, Softserve
@halyph(http://twitter.com/halyph)

Why don't you Groovy?

  • 1.
    Why Don't youGroovy? Engineering Communities 05 May 2016 Orest Ivasiv Software engineer, Softserve
  • 2.
  • 3.
    Disclaimer We will nottalk about Groovy language in details It's not a tutorial We are not Groovy haters/lovers. We are pragmatic devs Groovy is not a panacea, Groovy is a hammer Hipsters are not Groovy (it's 2016)
  • 4.
    Problems and Tasks Javadevs should not write scripts in Java Bash, Python, Ruby, etc. How to re-use existence Java knowledge in automation tasks How to choose the right scripting language How to automate on Windows, Linux and OSX
  • 5.
    Why Java isbad for scripting and automation? Tedious File and Network processing Tedious collection processing Tedious XML/JSON processing Verbose type declaration Limited DSL support Painful object construction code Just too verbose for small tasks Slow Edit-Compile-Run loop
  • 6.
  • 7.
    Scripts Run on allmajor OSs Easy to distribute Easy to read and maintain Reasonably small Quick Edit-Run cycle Performance is not important E.g. - Bash, Ruby, Python, Node.js, Groovy - Tcl, Lua
  • 8.
    Tools No sources "Fat" binary Popularor/and minimal runtime No runtime - single binary Very easy to distribute Low maintenance cost E.g. - Java/JVM, Go - C/C++, Python, Node.js
  • 9.
    Groovy JVM language Java, Scala,Clojure, Groovy, Kotlin Superb interoperability with Java Syntax is very similar to Java All Java libraries can be used in Groovy Almost all Java code is Groovy code Groovy language is full of modern features DSL
  • 10.
    Groovy is compiledLanguage Groovy is a dynamic language Dynamic != interpreted Interpreted == a runtime interprets an AST Groovy compiles down to JVM bytecode
  • 11.
  • 12.
  • 13.
  • 14.
    Launching a Jettyserver to serve Groovy templates @Grapes([ @Grab(group='org.eclipse.jetty.aggregate', module='jetty-server', version='8.1.7.v20120910'), @Grab(group='org.eclipse.jetty.aggregate', module='jetty-servlet', version='8.1.7.v20120910'), @Grab(group='javax.servlet', module='javax.servlet-api', version='3.0.1')]) import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.* import groovy.servlet.* def runServer(duration) { def server = new Server(8080) def context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); context.resourceBase = "." context.addServlet(TemplateServlet, "*.gsp") server.start() sleep duration server.stop() } runServer(10000)
  • 15.
    What's ugly inGroovy JVM and Groovy script start time is slow Limited OS-level scripting (see Python, Ruby) Groovy is another language. It’s not Java (thanks cap) Groovy is not well accepted in other communities Not convenient to use Groovy without IDE
  • 16.
    References Who is Groovy?by Cédric Champeau – history and people behind Groovy language (http://melix.github.io/blog/2015/02/who-is-groovy.html) Blog about Groovy, Gradle and Grails(http://mrhaki.blogspot.com) http://groovy-lang.org/(http://groovy-lang.org/) Groovy on the Shell(https://www.youtube.com/watch?v=1ogwSsl6EGQ) Curated list of awesome groovy libraries, frameworks and resourcesy(https://github.com/kdabir/awesome- groovy)
  • 17.
    Thank you 05 May2016 Tags: groovy(#ZgotmplZ) Orest Ivasiv Software engineer, Softserve @halyph(http://twitter.com/halyph)