39
Groovy and Noteworthy Izzet Mustafayev@EPAM Systems @webdizz http://webdizz.name

Groovy and noteworthy

Embed Size (px)

DESCRIPTION

What is Groovy. Why Groovy is an agile dynamic language? What makes Groovy special? Groovy tool set. Getting started from suggestions.

Citation preview

Page 1: Groovy and noteworthy

Groovy and

Noteworthy

Izzet Mustafayev@EPAM Systems @webdizzhttp://webdizz.name

Page 2: Groovy and noteworthy

Agenda

● Groovy

○ Specials

○ Basics

○ Infrastructure

● Demo

● Getting Started

Page 3: Groovy and noteworthy

GroovySpecials

Page 4: Groovy and noteworthy

Groovy is an agile dynamic language

Page 5: Groovy and noteworthy

println 'Hello World !'

Page 6: Groovy and noteworthy

Java is a Groovy but Groovy is not Java

Page 7: Groovy and noteworthy

Groovy supports DSL

Page 8: Groovy and noteworthy

Groovy supports DSL

● A flexible syntax

● Closures

● Meta-programming

● Operator overloading

● No dots and commas

Page 9: Groovy and noteworthy

Groovy provides statically type check

Page 10: Groovy and noteworthy

Groovy provides statically type check

@groovy.transform.TypeChecked void method() { // do nothing}

Page 11: Groovy and noteworthy

Groovy Basics

Page 12: Groovy and noteworthy

Groovy Shell

Page 13: Groovy and noteworthy

Omission of get/set methods

class Person { String name String email}

def person = new Person(name: 'me')person.email = '[email protected]'

println person.name// meprintln person.email// [email protected]

Page 14: Groovy and noteworthy

Initializing beans with named parameters

class Person { String name String email}

def person = new Person(name: 'me')person.email = '[email protected]'

println person.name// meprintln person.email// [email protected]

Page 15: Groovy and noteworthy

Context operations using with

class Person { String name String email}

def person = new Person(name: 'me', email: '[email protected]')

person.with{ println name// me println email// [email protected]}

Page 16: Groovy and noteworthy

GStrings (interpolation, multiline)

def param = 'param'def groovyString = """There is a ‘${param}’ param

"""

println groovyString // There is a ‘param’ param

Page 17: Groovy and noteworthy

Native syntax for data structures

def list = [1, 4, 6, 9]println list[-2] // 6

def map = [UA: 'Ukraine', UK: 'United Kingdom']println map.UA // Ukraine

def range = 10..20println range[2] //12

Page 18: Groovy and noteworthy

Elvis operator for default values

def name = null

println name != null ? name : "Unknown" // Unknown

println name ?: "Unknown" // Unknown

name = 'name'println name ?: "Unknown" // name

Page 19: Groovy and noteworthy

Safe graph navigationif (order != null) { if (order.getCustomer() != null) { if (order.getCustomer().getAddress() != null) {

Address address;address = order.getCustomer().getAddress()System.out.println(address);

} } }

println order?.customer?.address

Page 20: Groovy and noteworthy

Closures

printSum = { a, b -> print a+b }printSum(5, 7)// 12

upperCasedList = ['a','b','c','d']. collect{ it.toUpperCase() }

println upperCasedList // A, B, C, D

Page 21: Groovy and noteworthy

Metaprogramming

String.metaClass.cons2var = { ->String res = ''delegate.toLowerCase().tokenize('_').each{ s ->res+=res?s.capitalize():s

} res}

println "SAMPLE_VAR".cons2var()//sampleVar

Page 22: Groovy and noteworthy

Groovy Infrastructure

Page 23: Groovy and noteworthy

Gradle - http://gradle.org/

● Strong yet flexible conventions

● Manageable and understandable builds

● Follows convention over configuration approach

● Great plug-ins ecosystem

Page 24: Groovy and noteworthy

Spock - https://github.com/spockframework/spock

● Testing and specification framework

● JUnit compatible

● Highly expressive specification language

Page 25: Groovy and noteworthy

Easyb - http://easyb.org/

● Behavior driven development framework

● Specifications are written in Groovy and run via a Java runner,

command line, Maven or Ant

● Supports a few different styles of specifications ranging from

RSpec's it to a story based DSL with givens, whens, and thens

Page 26: Groovy and noteworthy

Grails - http://grails.org/

● Grails is an Open Source, full stack web

application framework for the JVM

● Based on Spring, Hibernate, Sitemesh, Quartz

etc.

● There are a lot of plug-ins

Page 27: Groovy and noteworthy

Griffon - http://griffon.codehaus.org

● Desktop development framework inspired in Grails

● Primarily Swing based however supports SWT,

Pivot, GTK and JavaFX too

● Growing plugin system (80+ plugins)

Page 28: Groovy and noteworthy

Gaelyk - http://gaelyk.appspot.com

● Google App Engine development framework

based on Groovy and Groovlets

● Emerging plugin system

Page 29: Groovy and noteworthy

GPars - http://gpars.codehaus.org/

● Provides DSL and concurrent friendly methods for

collections

● Supports Actors and STM

● Dataflow concurrency model

Page 30: Groovy and noteworthy

CodeNarc - http://codenarc.sourceforge.net/

● Static analysis for Groovy code

● Over 175 rules to detect defects, bad practices,

style issues etc.

● Build tools and Sonar integration

Page 31: Groovy and noteworthy

GVM - http://gvmtool.net/

● Manages parallel Versions of multiple SDKs

● Convenient command line interface

● Inspired by RVM

● Supports Groovy, Grails, Gradle etc

● Unfortunately does not work for Win

Page 32: Groovy and noteworthy

GroovyServ - http://kobo.github.io/groovyserv/

● Improves Groovy’s startup time

● Works for Win

Page 33: Groovy and noteworthy
Page 34: Groovy and noteworthy

Getting Started

Page 35: Groovy and noteworthy

http://groovy.codehaus.org/

Page 36: Groovy and noteworthy

Groovy in Action*

by Dierk König● Groovy committer since

2004

● Frequent conference

speaker

● Contributor to several agile

and testing books

Page 37: Groovy and noteworthy

Programming Groovy 2

by Venkat Subramaniam● An award-winning author

● Famous Agile Guru

● Frequent conference

speaker

Page 38: Groovy and noteworthy
Page 39: Groovy and noteworthy

Thank You!

Groovy and

NoteworthyIzzet Mustafayev@EPAM Systems

@webdizzhttp://webdizz.name