SlideShare a Scribd company logo
1 of 30
v
Groovy in production
Đào Văn Hiệp - 2018/08/10
Các vấn đề hiện tại?
Agenda:
- What is Groovy?
- How Groovy work?
- Why Groovy?
- Groovy vs Java
- Best practice with Groovy in production
Let's Go!
What is groovy?
Groovy is
A feature-rich
Java-friendly
Dynamic language *
For the Java platform
=> A super version of Java
What is a dynamic language?
A language that allows the types of variables to be changed at
runtime...
...among other things!
Difference between dynamic vs static language?
Groovy History
• 2003: Started by James Strachan and Bob McWhirter.
• 2004: Commissioned into JSR 241 but was almost abandoned.
• 2005: Brought back to life by Guillaume Laforge and Jeremy
• Rayner.
• 2007: Groovy 1.0.
• 2012: Groovy 2.0.
• 2014: Groovy 2.3 (official support for JDK 8)
• Now : Groovy 2.5 (Stable version)
Who use Groovy?
http://groovy-lang.org/
How Groovy work?
- Groovy runs in the JVM.
- GDK extend JDK
=> Groovy is syntactically aligned with Java.
- Compile to Bytecode like Java
Groovy Pos (vs. Java)
• Easy to learn
• Productivity (More concise and
meaningful code - Funny typing)
• Can call on Java classes. (Coding
link Java)
• Faster in develop, testing
• Addtional operators
• Mix Functional with Object Orient
Programming (Closure)
Groovy Cons (vs. Java)
• Nhiều lỗi tiềm ẩn với dynamic
coding: sai kiểu dữ liệu,....
• IDE không nhắc handle
exception
• Slower than Java
Demo
Groovy Features
• Closures
• Collection literals
• Properties (GroovyBeans or POGO)
• Multi-line strings
• String interpolation
• Default arguments
• Everything’s an Object (even numbers)
• Operator overloading
• GPath expressions
• Additional operators
• And much much more...
Closures are anonymous functions that:
o may accept parameters or return a value,
o can be assigned to variables,
o can be passed as arguments,
Demo
Groovy Closure
A both can take params, return value & do something, but...
Lambda expressions:
Language facility for implementing functional interfaces
• Interfaces with a single abstract method.
• Function, Predicate, Supplier, Consumer.
Groovy closures:
• Can be assign as variable
• Can be reference to default param by "it"
• Use like Functional Programming
Groovy Closure <> Java 8 Lambda
Groovy best practices
"def" keyword
Người đọc không hiểu dữ liệu trả về.
(Đặc biệt với đoạn dài)
=> Gây khó khi đọc hiểu & maintain
Don't use "if" with Object
Groovy truth and equals
• Null value is false.
• Empty collection or map is false.
• Empty string is false.
• Zero value is false.
Best pratices:
- Chỉ nên sử dụng với Boolean
- Các trường hợp dùng với Type Number
rất dễ nhầm
- Các trường hợp check List/String nên
check cả null
(StringUtils.notBlank()/CollectionUtils.notEmpty())
Don't use "if" with Object
• GString. (Double quote: "This is GString: ${1 + 1}")
Can be calculate, evaluate method....
• String.
• Single quote: 'This is String'
• Double quote: "This is String" - Like Java String
=> Don't use GString when unnecessary (String constant)
String vs GString
Use multiple line
String vs GString
"?:" operator
=> Hữu dụng khi dùng để set default
value
Vấn đề:
- Các trường hợp String blank hoặc Number
value 0
- KQ: 10 & 10​
Null Safe operator
With Null safe
Without Null safe
with() method
Check condition
Set multiple value
Use like builder
Collection In Groovy
• Find/Filter
• Map
• List to Map
• Grep (exclude null, empty elements)
Format Map, Json
Before
After
• Use operator : '==' (compare String), '=~' (Check regular/Contains)
• Operator: '+', '-' (add, remove with List)
• Parse Date: Date.parse(...), Date.format(...)
Groovy best practices (Continues)
• Annotations:
• @InheritConstructors
• @TupleConstructor
• @Slf4j
• @CompileStatic
• @Singleton
Groovy best practices (Continues)
• Groovy 2 Cookbook
• Programming Groovy 2
• Blog: http://mrhaki.blogspot.com
• Groovy Web Site: http://groovy.codehaus.org
How to start with Groovy?
Groovy best pratices at EWAY

More Related Content

What's hot

Jug dynamic languages_in_jvm
Jug dynamic languages_in_jvmJug dynamic languages_in_jvm
Jug dynamic languages_in_jvmDmitry Buzdin
 
Over 9000: JRuby in 2015
Over 9000: JRuby in 2015Over 9000: JRuby in 2015
Over 9000: JRuby in 2015Charles Nutter
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
When Javascript isn't Javascript
When Javascript isn't Javascript When Javascript isn't Javascript
When Javascript isn't Javascript Tristan Gomez
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScriptOffirmo
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devopsRob Kinyon
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript FundamentalsSunny Sharma
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascriptAndrei Sebastian Cîmpean
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
 
Ruby on Rails: a brief introduction
Ruby on Rails: a brief introductionRuby on Rails: a brief introduction
Ruby on Rails: a brief introductionLuigi De Russis
 
Node.js Patterns and Opinions
Node.js Patterns and OpinionsNode.js Patterns and Opinions
Node.js Patterns and OpinionsIsaacSchlueter
 
NoSQL Yes, But YesCQL, No?
NoSQL Yes, But YesCQL, No?NoSQL Yes, But YesCQL, No?
NoSQL Yes, But YesCQL, No?Eric Evans
 
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Codemotion
 

What's hot (20)

Jug dynamic languages_in_jvm
Jug dynamic languages_in_jvmJug dynamic languages_in_jvm
Jug dynamic languages_in_jvm
 
JRuby: The Hard Parts
JRuby: The Hard PartsJRuby: The Hard Parts
JRuby: The Hard Parts
 
Over 9000: JRuby in 2015
Over 9000: JRuby in 2015Over 9000: JRuby in 2015
Over 9000: JRuby in 2015
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
When Javascript isn't Javascript
When Javascript isn't Javascript When Javascript isn't Javascript
When Javascript isn't Javascript
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devops
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascript
 
Ruby
RubyRuby
Ruby
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Ruby on Rails: a brief introduction
Ruby on Rails: a brief introductionRuby on Rails: a brief introduction
Ruby on Rails: a brief introduction
 
Perl5 VS JSON
Perl5 VS JSONPerl5 VS JSON
Perl5 VS JSON
 
Node.js Patterns and Opinions
Node.js Patterns and OpinionsNode.js Patterns and Opinions
Node.js Patterns and Opinions
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
TypeScript
TypeScriptTypeScript
TypeScript
 
NoSQL Yes, But YesCQL, No?
NoSQL Yes, But YesCQL, No?NoSQL Yes, But YesCQL, No?
NoSQL Yes, But YesCQL, No?
 
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
Daniele Esposti - Evolution or stagnation programming languages - Codemotion ...
 

Similar to Groovy best pratices at EWAY

javerosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparisonjaverosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparisonDomingo Suarez Torres
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to GroovyKevin H.A. Tan
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersKostas Saidis
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails IntroductionEric Weimer
 
eXo EC - Groovy Programming Language
eXo EC - Groovy Programming LanguageeXo EC - Groovy Programming Language
eXo EC - Groovy Programming LanguageHoat Le
 
What would your own version of Ruby look like? (RubyKaigi)
What would your own version of Ruby look like? (RubyKaigi)What would your own version of Ruby look like? (RubyKaigi)
What would your own version of Ruby look like? (RubyKaigi)Hung Wu Lo
 
WeCode IL: Confessions of a java developer that fell in love with the groovy...
WeCode IL:  Confessions of a java developer that fell in love with the groovy...WeCode IL:  Confessions of a java developer that fell in love with the groovy...
WeCode IL: Confessions of a java developer that fell in love with the groovy...Victor Trakhtenberg
 
JRuby - The Perfect Alternative
JRuby - The Perfect AlternativeJRuby - The Perfect Alternative
JRuby - The Perfect AlternativeRam Vijapurapu
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesPéter Verhás
 
What would your own version of Ruby look like?
What would your own version of Ruby look like?What would your own version of Ruby look like?
What would your own version of Ruby look like?Hung Wu Lo
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |ShubhamAthawane
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
Groovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesGroovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesDarren Cruse
 

Similar to Groovy best pratices at EWAY (20)

javerosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparisonjaverosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparison
 
Groovy intro
Groovy introGroovy intro
Groovy intro
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
 
Groovy And Grails
Groovy And GrailsGroovy And Grails
Groovy And Grails
 
Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 
Java script core
Java script coreJava script core
Java script core
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
 
eXo EC - Groovy Programming Language
eXo EC - Groovy Programming LanguageeXo EC - Groovy Programming Language
eXo EC - Groovy Programming Language
 
What would your own version of Ruby look like? (RubyKaigi)
What would your own version of Ruby look like? (RubyKaigi)What would your own version of Ruby look like? (RubyKaigi)
What would your own version of Ruby look like? (RubyKaigi)
 
WeCode IL: Confessions of a java developer that fell in love with the groovy...
WeCode IL:  Confessions of a java developer that fell in love with the groovy...WeCode IL:  Confessions of a java developer that fell in love with the groovy...
WeCode IL: Confessions of a java developer that fell in love with the groovy...
 
Groovy on Android
Groovy on AndroidGroovy on Android
Groovy on Android
 
Golang
GolangGolang
Golang
 
JRuby - The Perfect Alternative
JRuby - The Perfect AlternativeJRuby - The Perfect Alternative
JRuby - The Perfect Alternative
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value Types
 
What would your own version of Ruby look like?
What would your own version of Ruby look like?What would your own version of Ruby look like?
What would your own version of Ruby look like?
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Groovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesGroovy Metaprogramming for Dummies
Groovy Metaprogramming for Dummies
 
Groovy
GroovyGroovy
Groovy
 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Groovy best pratices at EWAY

  • 1. v Groovy in production Đào Văn Hiệp - 2018/08/10
  • 2. Các vấn đề hiện tại?
  • 3. Agenda: - What is Groovy? - How Groovy work? - Why Groovy? - Groovy vs Java - Best practice with Groovy in production
  • 5. What is groovy? Groovy is A feature-rich Java-friendly Dynamic language * For the Java platform => A super version of Java
  • 6. What is a dynamic language? A language that allows the types of variables to be changed at runtime... ...among other things! Difference between dynamic vs static language?
  • 7. Groovy History • 2003: Started by James Strachan and Bob McWhirter. • 2004: Commissioned into JSR 241 but was almost abandoned. • 2005: Brought back to life by Guillaume Laforge and Jeremy • Rayner. • 2007: Groovy 1.0. • 2012: Groovy 2.0. • 2014: Groovy 2.3 (official support for JDK 8) • Now : Groovy 2.5 (Stable version)
  • 9. How Groovy work? - Groovy runs in the JVM. - GDK extend JDK => Groovy is syntactically aligned with Java. - Compile to Bytecode like Java
  • 10. Groovy Pos (vs. Java) • Easy to learn • Productivity (More concise and meaningful code - Funny typing) • Can call on Java classes. (Coding link Java) • Faster in develop, testing • Addtional operators • Mix Functional with Object Orient Programming (Closure)
  • 11. Groovy Cons (vs. Java) • Nhiều lỗi tiềm ẩn với dynamic coding: sai kiểu dữ liệu,.... • IDE không nhắc handle exception • Slower than Java
  • 12. Demo
  • 13. Groovy Features • Closures • Collection literals • Properties (GroovyBeans or POGO) • Multi-line strings • String interpolation • Default arguments • Everything’s an Object (even numbers) • Operator overloading • GPath expressions • Additional operators • And much much more...
  • 14. Closures are anonymous functions that: o may accept parameters or return a value, o can be assigned to variables, o can be passed as arguments, Demo Groovy Closure
  • 15. A both can take params, return value & do something, but... Lambda expressions: Language facility for implementing functional interfaces • Interfaces with a single abstract method. • Function, Predicate, Supplier, Consumer. Groovy closures: • Can be assign as variable • Can be reference to default param by "it" • Use like Functional Programming Groovy Closure <> Java 8 Lambda
  • 17. "def" keyword Người đọc không hiểu dữ liệu trả về. (Đặc biệt với đoạn dài) => Gây khó khi đọc hiểu & maintain
  • 18. Don't use "if" with Object Groovy truth and equals • Null value is false. • Empty collection or map is false. • Empty string is false. • Zero value is false. Best pratices: - Chỉ nên sử dụng với Boolean - Các trường hợp dùng với Type Number rất dễ nhầm - Các trường hợp check List/String nên check cả null (StringUtils.notBlank()/CollectionUtils.notEmpty())
  • 19. Don't use "if" with Object
  • 20. • GString. (Double quote: "This is GString: ${1 + 1}") Can be calculate, evaluate method.... • String. • Single quote: 'This is String' • Double quote: "This is String" - Like Java String => Don't use GString when unnecessary (String constant) String vs GString
  • 22. "?:" operator => Hữu dụng khi dùng để set default value Vấn đề: - Các trường hợp String blank hoặc Number value 0 - KQ: 10 & 10​
  • 23. Null Safe operator With Null safe Without Null safe
  • 24. with() method Check condition Set multiple value Use like builder
  • 25. Collection In Groovy • Find/Filter • Map • List to Map • Grep (exclude null, empty elements)
  • 27. • Use operator : '==' (compare String), '=~' (Check regular/Contains) • Operator: '+', '-' (add, remove with List) • Parse Date: Date.parse(...), Date.format(...) Groovy best practices (Continues)
  • 28. • Annotations: • @InheritConstructors • @TupleConstructor • @Slf4j • @CompileStatic • @Singleton Groovy best practices (Continues)
  • 29. • Groovy 2 Cookbook • Programming Groovy 2 • Blog: http://mrhaki.blogspot.com • Groovy Web Site: http://groovy.codehaus.org How to start with Groovy?