SlideShare a Scribd company logo
JVM. quack() or Groovy vs Ceremony
…
Stas Shevchenko
Java Launch, 23/04/2013, Riga
Java Language comes with
• Design Patterns
• Boilerplate
• Overly Ceremony code
1. Patterns
…
Boilerplate
2. Boilerplate
-   getter/setters
-   Lazy init factories
-   toString, hashCode, equals
-   Explicit Exception declaration/handling
-   Close for resources
-   synchronization
Ceremony: Code’s Worst Enemy
Code Today (Death Star)


               ESSENCE




      CEREMONY
Future: Paradigm, Languages,
         Frameworks

 CEREMONY




            ESSENCE
3. Ceremony to Essence code. Step 0
public ActionForward edit(ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response)
     throws Exception {
   PersonForm personForm = (PersonForm) form;
   if (personForm.getId() != null) {
     PersonManager mgr = (PersonManager) getBean("personManager");
     Person person = mgr.getPerson(personForm.getId());
     personForm = (PersonForm) convert(person);
     updateFormBean(mapping, request, personForm);
   }
   return mapping.findForward("edit");
 }
Step 1. Duck Typing
edit(mapping, form, request, response)
    throws Exception {
  personForm = form;
  if (personForm.getId() != null) {
    mgr = getBean("personManager");
    person = mgr.getPerson(personForm.getId());
    personForm = convert(person);
    updateFormBean(mapping, request, personForm);
  }
  return mapping.findForward("edit");
}
Step 2. duck typing, without local
                variable
edit(mapping, form, request, response)
    throws Exception {
  if (form.getId() != null) {
    mgr = getBean("personManager");
    person = mgr.getPerson(form.getId());
    form = convert(person);
    updateFormBean(mapping, request, form);
  }
  return mapping.findForward("edit");
}
Step 3. Implicit return, exceptions
edit(mapping, form, request, response) {
  if (form.getId() != null) {
    mgr = getBean("personManager");
    person = mgr.getPerson(form.getId());
    form = convert(person);
    updateFormBean(mapping, request, form);
  }
  mapping.findForward("edit");
}
Step 4. Don't add a manager layer to
       MVC (yet). KISS + YAGNI.
edit(mapping, form, request, response) {
   if (form.getId() != null) {
     person = Person.find(form.getId());
     form = convert(person);
     updateFormBean(mapping, request, form);
   }
   mapping.findForward("edit");
 }
Step 5. Conditionals make code
            expensive to test
edit(mapping, form, request, response) {
   person = Person.find(form.getId());
   form = convert(person);
   updateFormBean(mapping, request, form);
   mapping.findForward("edit");
 }
Step 6. All action methods have the
        same four arguments
edit() {
  person = Person.find(form.getId());
  form = convert(person);
  updateFormBean(mapping, request, form);
  mapping.findForward("edit");
}
Step 7. Delegate object showing to
                 form
edit() {
  person = Person.find(form.getId());
  mapping.findForward("edit");
}
Step 8. Standard routing
edit() {
  person = Person.find(form.getId());
}

Or Ruby
def edit
  @person = Person.find(params[:id])
 end
Java Word
IoC
Aspects
Lombok or Eclipse Xtend
Code generators -> Spring Roo
JVM Languages
    Clojure
     Scala
    Groovy
     JRuby
    Jython
  Java Script
Clojure
- Lisp – WTF?
- By default Functional Programming only
Scala
- Syntax WTF
- Acclimatization period 6 to 12 months
JRuby
- Ruby guys
- gemns hell
Jython
- Python syntax ((
Java Script (Rhino)
- Is Java Script
Starting Groovy
1. Download the .zip file from
   http://groovy.codehaus.org and unzip it to
   local drive
2. Create the GROOVY_HOME environment
   variable and add $GROOVY_HOME/bin to
   you path
3. type groovy -version
Groovy Console
Primitives
3.times { println it }

assert (10 instanceof Integer)

println 4.4.class

String s = 10 as String;
println s;
Groovy Beans
class Customer {
   Integer id
   def name
   Date dob
}


def customer = new Customer(id:1, name:"Gromit",
dob:new Date())
Collections – Lists, Ranges
def list = [5, 6, 7, 8]
assert list[2] == 7
assert list instanceof java.util.List

def range = 5..8
assert range.size() == 4
assert range[2] == 7
assert range instanceof java.util.List
Collections - Map
def map = [name:"Gromit", likes:"cheese",
id:1234]
assert map["name"] == "Gromit"
assert map['id'] == 1234
assert map instanceof java.util.Map
Collections features
assert [1, 3, 5] == ['a', 'few', 'words']*.size()

def words = ['ant', 'buffalo', 'cat', 'dinosaur']
assert words.findAll{ w -> w.size() > 4 } == ['buffalo',
'dinosaur']

def words = ['ant', 'buffalo', 'cat', 'dinosaur']
assert words.collect{ it[0] } == ['a', 'b', 'c', 'd']

def sub = list[1, 3, 20..25, 33]
assert sub == [101, 103, 120, 121, 122, 123, 124, 125, 133]
Duck typing
// Hey duck
Duck myDuck = new Duck()
myDuck.quack()

// Hey quacker
def duck = new Duck()
myDuck.quack()
Duck typing 2
class Duck {
   def quack() {println("quack")}
}

def action = "quack"
def duck = new Duck()
duck."${action}"()
Operators
a == b     a.equals(b)
a+b        a.plus(b)
a-b        a.minus(b)
a++        a.next()
a << b     a.leftShift(b)

def groovy = *”beer", ”rock&roll"]
groovy << ”girls"
Closures
def squareClosure = { value ->
  value * value;
}

assert (4 == squareClosure(2))
IO
def file = new File(sms.txt).eachLine{ println it }

file.write(”rewrite file”)

file.append(“add to file”)
file << ”sexy style"
XML
def xml = new groovy.xml.MarkupBuilder()
xml.goods(type:”current”){
  good(“Beer”)
  good (“Rock&Roll”)
  good (“Girls”)
}
XML
def goods = new XmlSlurper().parseText(…)
def allGoods = records.name
assert 3 == allRecords.size()
def allNodes = goods.depthFirst().collect{ it }
def firstGood = goods.name[0]
assert ’sms’ == firstGood .name()
assert ‘Text’ == firstGood.@make.text()
DSL
This is a really cool topic, where the stars are
began…

• A DSL allows expressions in a domain specific
  manner
• Method pointers make this easy:
def list = []
def
  insert = list.&add
insert ”beer"
insert
  ”rock&roll"
Something to read
Groovy++
Grails -> GORM
Gradle
At the end – NPE fighter in my team
infringementAction.setCustomsOffice(
 versionedReplyInf != null ?
 (versionedReplyInf.getReplyInf() != null ?
  (versionedReplyInf.getReplyInf().getInf() != null ?
   (versionedReplyInf.getReplyInf().getInf().getInf() != null ?
    (versionedReplyInf.getReplyInf().getInf().getInf().
                                   getCustomsOffice() != null ?
         versionedReplyInf.getReplyInf().getInf().getInf().
             getCustomsOffice()
                : null) : null) : null) : null) : null);
At the end on Groovy
Safe navigation operator “?.”

infringementAction.setCustomsOffice(
versionedReplyInf?.getReplyInf()?.getInf()?.
getInf()?.getCustomsOffice())

More Related Content

What's hot

Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
Husain Dalal
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
Aleksandar Veselinovic
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
osfameron
 
Swift rocks! #1
Swift rocks! #1Swift rocks! #1
Swift rocks! #1
Hackraft
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And Monad
Oliver Daff
 
Hammurabi
HammurabiHammurabi
Hammurabi
Mario Fusco
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
Muthu Vinayagam
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
Hackraft
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
LearningTech
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
LearningTech
 
RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017
Wanbok Choi
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
Jongsoo Lee
 
Ciklum net sat12112011-alexander fomin-expressions and all, all, all
Ciklum net sat12112011-alexander fomin-expressions and all, all, allCiklum net sat12112011-alexander fomin-expressions and all, all, all
Ciklum net sat12112011-alexander fomin-expressions and all, all, allCiklum Ukraine
 
Collection v3
Collection v3Collection v3
Collection v3
Sunil OS
 
Java cheatsheet
Java cheatsheetJava cheatsheet
Java cheatsheet
Anass SABANI
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
OOP v3
OOP v3OOP v3
OOP v3
Sunil OS
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
greenwop
 
One Monad to Rule Them All
One Monad to Rule Them AllOne Monad to Rule Them All
One Monad to Rule Them All
John De Goes
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
Paulo Morgado
 

What's hot (20)

Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 
Swift rocks! #1
Swift rocks! #1Swift rocks! #1
Swift rocks! #1
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And Monad
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
 
RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017RxSwift 활용하기 - Let'Swift 2017
RxSwift 활용하기 - Let'Swift 2017
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 
Ciklum net sat12112011-alexander fomin-expressions and all, all, all
Ciklum net sat12112011-alexander fomin-expressions and all, all, allCiklum net sat12112011-alexander fomin-expressions and all, all, all
Ciklum net sat12112011-alexander fomin-expressions and all, all, all
 
Collection v3
Collection v3Collection v3
Collection v3
 
Java cheatsheet
Java cheatsheetJava cheatsheet
Java cheatsheet
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
OOP v3
OOP v3OOP v3
OOP v3
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
One Monad to Rule Them All
One Monad to Rule Them AllOne Monad to Rule Them All
One Monad to Rule Them All
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 

Similar to Groovy vs Boilerplate and Ceremony Code

Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
André Faria Gomes
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Tsuyoshi Yamamoto
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
DataMapper
DataMapperDataMapper
DataMapper
Yehuda Katz
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
Jonathan Felch
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
niklal
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
Michael Girouard
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
Groovy
GroovyGroovy
Groovy
Zen Urban
 
JQuery-Tutorial" />
  JQuery-Tutorial" />  JQuery-Tutorial" />
JQuery-Tutorial" />tutorialsruby
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentationguestcf600a
 
Rails Presentation - Technology Books, Tech Conferences
 Rails Presentation - Technology Books, Tech Conferences Rails Presentation - Technology Books, Tech Conferences
Rails Presentation - Technology Books, Tech Conferencestutorialsruby
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentationguestcf600a
 
GoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDGoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDD
Bartłomiej Kiełbasa
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
(first '(Clojure.))
(first '(Clojure.))(first '(Clojure.))
(first '(Clojure.))
niklal
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
JAVASCRIPT CHEAT SHEET PDF
JAVASCRIPT CHEAT SHEET PDFJAVASCRIPT CHEAT SHEET PDF
JAVASCRIPT CHEAT SHEET PDF
ElliotBrenyaSaerfo
 

Similar to Groovy vs Boilerplate and Ceremony Code (20)

Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
DataMapper
DataMapperDataMapper
DataMapper
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Groovy
GroovyGroovy
Groovy
 
JQuery-Tutorial" />
  JQuery-Tutorial" />  JQuery-Tutorial" />
JQuery-Tutorial" />
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentation
 
Rails Presentation - Technology Books, Tech Conferences
 Rails Presentation - Technology Books, Tech Conferences Rails Presentation - Technology Books, Tech Conferences
Rails Presentation - Technology Books, Tech Conferences
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentation
 
GoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDGoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDD
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Latinoware
LatinowareLatinoware
Latinoware
 
(first '(Clojure.))
(first '(Clojure.))(first '(Clojure.))
(first '(Clojure.))
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
JAVASCRIPT CHEAT SHEET PDF
JAVASCRIPT CHEAT SHEET PDFJAVASCRIPT CHEAT SHEET PDF
JAVASCRIPT CHEAT SHEET PDF
 

Recently uploaded

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 

Recently uploaded (20)

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 

Groovy vs Boilerplate and Ceremony Code

  • 1. JVM. quack() or Groovy vs Ceremony
  • 3. Java Language comes with • Design Patterns • Boilerplate • Overly Ceremony code
  • 6. 2. Boilerplate - getter/setters - Lazy init factories - toString, hashCode, equals - Explicit Exception declaration/handling - Close for resources - synchronization
  • 8. Code Today (Death Star) ESSENCE CEREMONY
  • 9. Future: Paradigm, Languages, Frameworks CEREMONY ESSENCE
  • 10. 3. Ceremony to Essence code. Step 0 public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { PersonForm personForm = (PersonForm) form; if (personForm.getId() != null) { PersonManager mgr = (PersonManager) getBean("personManager"); Person person = mgr.getPerson(personForm.getId()); personForm = (PersonForm) convert(person); updateFormBean(mapping, request, personForm); } return mapping.findForward("edit"); }
  • 11. Step 1. Duck Typing edit(mapping, form, request, response) throws Exception { personForm = form; if (personForm.getId() != null) { mgr = getBean("personManager"); person = mgr.getPerson(personForm.getId()); personForm = convert(person); updateFormBean(mapping, request, personForm); } return mapping.findForward("edit"); }
  • 12. Step 2. duck typing, without local variable edit(mapping, form, request, response) throws Exception { if (form.getId() != null) { mgr = getBean("personManager"); person = mgr.getPerson(form.getId()); form = convert(person); updateFormBean(mapping, request, form); } return mapping.findForward("edit"); }
  • 13. Step 3. Implicit return, exceptions edit(mapping, form, request, response) { if (form.getId() != null) { mgr = getBean("personManager"); person = mgr.getPerson(form.getId()); form = convert(person); updateFormBean(mapping, request, form); } mapping.findForward("edit"); }
  • 14. Step 4. Don't add a manager layer to MVC (yet). KISS + YAGNI. edit(mapping, form, request, response) { if (form.getId() != null) { person = Person.find(form.getId()); form = convert(person); updateFormBean(mapping, request, form); } mapping.findForward("edit"); }
  • 15. Step 5. Conditionals make code expensive to test edit(mapping, form, request, response) { person = Person.find(form.getId()); form = convert(person); updateFormBean(mapping, request, form); mapping.findForward("edit"); }
  • 16. Step 6. All action methods have the same four arguments edit() { person = Person.find(form.getId()); form = convert(person); updateFormBean(mapping, request, form); mapping.findForward("edit"); }
  • 17. Step 7. Delegate object showing to form edit() { person = Person.find(form.getId()); mapping.findForward("edit"); }
  • 18. Step 8. Standard routing edit() { person = Person.find(form.getId()); } Or Ruby def edit @person = Person.find(params[:id]) end
  • 19. Java Word IoC Aspects Lombok or Eclipse Xtend Code generators -> Spring Roo
  • 20. JVM Languages Clojure Scala Groovy JRuby Jython Java Script
  • 21. Clojure - Lisp – WTF? - By default Functional Programming only
  • 22. Scala - Syntax WTF - Acclimatization period 6 to 12 months
  • 23. JRuby - Ruby guys - gemns hell
  • 25. Java Script (Rhino) - Is Java Script
  • 26. Starting Groovy 1. Download the .zip file from http://groovy.codehaus.org and unzip it to local drive 2. Create the GROOVY_HOME environment variable and add $GROOVY_HOME/bin to you path 3. type groovy -version
  • 28. Primitives 3.times { println it } assert (10 instanceof Integer) println 4.4.class String s = 10 as String; println s;
  • 29. Groovy Beans class Customer { Integer id def name Date dob } def customer = new Customer(id:1, name:"Gromit", dob:new Date())
  • 30. Collections – Lists, Ranges def list = [5, 6, 7, 8] assert list[2] == 7 assert list instanceof java.util.List def range = 5..8 assert range.size() == 4 assert range[2] == 7 assert range instanceof java.util.List
  • 31. Collections - Map def map = [name:"Gromit", likes:"cheese", id:1234] assert map["name"] == "Gromit" assert map['id'] == 1234 assert map instanceof java.util.Map
  • 32. Collections features assert [1, 3, 5] == ['a', 'few', 'words']*.size() def words = ['ant', 'buffalo', 'cat', 'dinosaur'] assert words.findAll{ w -> w.size() > 4 } == ['buffalo', 'dinosaur'] def words = ['ant', 'buffalo', 'cat', 'dinosaur'] assert words.collect{ it[0] } == ['a', 'b', 'c', 'd'] def sub = list[1, 3, 20..25, 33] assert sub == [101, 103, 120, 121, 122, 123, 124, 125, 133]
  • 33. Duck typing // Hey duck Duck myDuck = new Duck()
myDuck.quack() // Hey quacker def duck = new Duck()
myDuck.quack()
  • 34. Duck typing 2 class Duck { def quack() {println("quack")} } def action = "quack" def duck = new Duck() duck."${action}"()
  • 35. Operators a == b a.equals(b) a+b a.plus(b) a-b a.minus(b) a++ a.next() a << b a.leftShift(b) def groovy = *”beer", ”rock&roll"] groovy << ”girls"
  • 36. Closures def squareClosure = { value -> value * value; } assert (4 == squareClosure(2))
  • 37. IO def file = new File(sms.txt).eachLine{ println it } file.write(”rewrite file”) file.append(“add to file”)
file << ”sexy style"
  • 38. XML def xml = new groovy.xml.MarkupBuilder() xml.goods(type:”current”){ good(“Beer”) good (“Rock&Roll”) good (“Girls”) }
  • 39. XML def goods = new XmlSlurper().parseText(…) def allGoods = records.name assert 3 == allRecords.size() def allNodes = goods.depthFirst().collect{ it } def firstGood = goods.name[0] assert ’sms’ == firstGood .name() assert ‘Text’ == firstGood.@make.text()
  • 40. DSL This is a really cool topic, where the stars are began… • A DSL allows expressions in a domain specific manner • Method pointers make this easy:
def list = []
def insert = list.&add
insert ”beer"
insert ”rock&roll"
  • 42. At the end – NPE fighter in my team infringementAction.setCustomsOffice( versionedReplyInf != null ? (versionedReplyInf.getReplyInf() != null ? (versionedReplyInf.getReplyInf().getInf() != null ? (versionedReplyInf.getReplyInf().getInf().getInf() != null ? (versionedReplyInf.getReplyInf().getInf().getInf(). getCustomsOffice() != null ? versionedReplyInf.getReplyInf().getInf().getInf(). getCustomsOffice() : null) : null) : null) : null) : null);
  • 43. At the end on Groovy Safe navigation operator “?.” infringementAction.setCustomsOffice( versionedReplyInf?.getReplyInf()?.getInf()?. getInf()?.getCustomsOffice())