SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
DSL로 만나는 Groovy
장시영
KGGUG
DSL
•DSLR? DSL?
A domain-specific language (DSL) is a computer language specialized to a
particular application domain.
http://en.wikipedia.org/wiki/Domain-specific_language
http://www.aladin.co.kr/shop/wproduct.aspx?ISBN=8991268994

•DSL <-> GPL(General Purpose Language)
•DSL = Mini Languages
•DSL Example => XML, HTML, CSS, SQL
•Groovy로 해석되는 DSL
– 각종 Builder, GORM, gradle, Grails
Groovy?
•
•
•
•

Ruby?
Dynamic Language?
다양한 빌더
Grails, gradle, GORM 등
Groovy Builder DSL – XML
writer = new StringWriter()
builder = new groovy.xml.MarkupBuilder(writer)
builder.numbers {
description 'Squares and factors of 10..15'
for (i in 10..15) {
number (value: i, square: i*i) {
//#1
for ( j in 2..<i) {
if (i % j == 0) {
factor (value: j) //#2
}
}
}
}
}
println writer
http://groovyconsole.appspot.com/
Groovy Builder DSL - HTML
def writer = new StringWriter()
def html = new groovy.xml.MarkupBuilder(writer)
html.html {
head { title 'Constructed by MarkupBuilder' }
body {
h1 'What can I do with MarkupBuilder?'
form (action:'whatever') {
for (line in [
'Produce HTML',
'Produce XML',
'Have some fun'
]){
input(type:'checkbox',checked:'checked', id:line, '')
label(for:line, line)
br('')
}
}
}
}
println writer
GORM – DSL
• ORM DSL

– Mapping

• Table, Column mapping
• Relational mapping

– ORM관련 설정
•
•
•
•

Cache 전략
Custom ID 전략
Composite Primary Keys
Index 설정

– http://grails.org/doc/latest/guide/single.html#ormdsl

• Query DSL
–

Basic Query

• list, get, getAll

– Dynamic Finders
• findByXXX
–
–

Book.findByTitle(„정글만리‟), findByTitleLike(„%정글‟)
http://grails.org/doc/latest/ref/Domain%20Classes/findBy.html
Groovy로 만든 한글 DSL
Object.metaClass.을 =
Object.metaClass.를 =
Object.metaClass.의 =
{ clos -> clos(delegate) }
먼저 = { it }
표시하라 = { println it }
제곱근 = { Math.sqrt(it) }
먼저 100 의 제곱근 을 표시하라
먼저(100).의(제곱근).을(표시하라)
출처: http://it.gilbird.com/textyle/8318
Groovy는 왜 DSL에 강한가?
• Dynamic Language

– Dynamic Type
num = 10; str = “20”
assert num instanceof Integer
assert str instanceof String
– Closure
• Caller에게 양보하기
– MOP(Meta Class, Expando Class)
• 요술상자, 아메바
– Groovy‟s chain method calls (GEP 3)
• 괄호 빼기
먼저 100 의 제곱근 을 표시하라
먼저(100).의(제곱근).을(표시하라)

•

JVM 기반

– Groovy는 결국 Java Class로 컴파일
– 거의 95%이상 Java와 동일하게 코딩 가능
– Java와 Groovy의 혼용
Groovy MOP
• MOP(Meta Object Protocol)
– MetaObjectProtocol
• http://en.wikipedia.org/wiki/Metaobject
• MetaClass, ExpandoMetaClass
http://mrhaki.blogspot.kr/2009/10/groovy-goodness-expando-as-dynamic-bean.html

– 요술을 부리는 MOP Hooks
• invokeMethod, methodMissing, get/setProperty,
propertyMissing
Groovy MetaClass
MOP Hooks - invokeMethod
import org.codehaus.groovy.runtime.StringBufferWriter
import org.codehaus.groovy.runtime.InvokerHelper
class Traceable implements GroovyInterceptable {
Writer writer = new PrintWriter(System.out)
private int indent = 0
Object invokeMethod(String name, Object args){
writer.write("n" + ' '*indent + "before method '$name'")
writer.flush()
indent++
def metaClass = InvokerHelper.getMetaClass(this)
def result = metaClass.invokeMethod(this, name, args)
indent-writer.write("n" + ' '*indent + "after method '$name'")
writer.flush()
return result
}
}
class Whatever extends Traceable {
int outer(){
return inner()
}
int inner(){
return 1
}
}
def log = new StringBuffer()
def traceMe = new Whatever(writer: new StringBufferWriter(log))
assert 1 == traceMe.outer()
println log
Method 실행 순서
MOP Hooks – methodMissing
class GORM {

}

def dynamicMethods = [...] // an array of dynamic methods that use regex
def methodMissing(String name, args) {
def method = dynamicMethods.find { it.match(name) }
if(method) {
GORM.metaClass."$name" = { Object[] varArgs ->
method.invoke(delegate, name, varArgs)
}
return method.invoke(delegate,name, args)
}
else throw new MissingMethodException(name, delegate, args)
}

http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing
Groovy Closure
def lineFile = new File(getClass().getResource("numbers.txt").getPath())
def sumValue = 0, multiflyValue = 1, concateValue = ''
lineFile.eachLine {
sumValue += Integer.parseInt(it)
multiflyValue *= Integer.parseInt(it)
concateValue += it
}
assert sumValue == 10
assert multiflyValue == 24
assert concateValue == '1234'
한국어 DSL로 돌아와서
Object.metaClass.을 =
Object.metaClass.를 =
Object.metaClass.의 =
{ clos -> clos(delegate) }
먼저 = { it }
표시하라 = { println it }
제곱근 = { Math.sqrt(it) }
먼저 100 의 제곱근 을 표시하라
먼저(100).의(제곱근).을(표시하라)
100.제곱근 을 표시하라
출처: http://it.gilbird.com/textyle/8318
관련 자료
• http://notes.3kbo.com/groovy-dsls
• http://en.wikipedia.org/wiki/Domainspecific_language
• DSL 번역본
• 프로그래밍 그루비
• 한국어 DSL
• Groovy for Domain-Specific Languages
• http://en.wikipedia.org/wiki/Metaobject
• http://groovy.codehaus.org/api/overviewsummary.html
• Groovy Grails 의 좋은 점
• ★ Groovy

Más contenido relacionado

La actualidad más candente

Venkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In GroovyVenkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In Groovydeimos
 
JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!Iván López Martín
 
Pluggable web app using Angular (Odessa JS conf)
Pluggable web app using Angular (Odessa JS conf)Pluggable web app using Angular (Odessa JS conf)
Pluggable web app using Angular (Odessa JS conf)Saif Jerbi
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Web Development: Making it the right way
Web Development: Making it the right wayWeb Development: Making it the right way
Web Development: Making it the right wayYagiz Nizipli
 
Quick Review of Desktop and Native Apps using Javascript
Quick Review of Desktop and Native Apps using JavascriptQuick Review of Desktop and Native Apps using Javascript
Quick Review of Desktop and Native Apps using JavascriptRobert Ellen
 
Intro to Crystal Programming Language
Intro to Crystal Programming LanguageIntro to Crystal Programming Language
Intro to Crystal Programming LanguageAdler Hsieh
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go langAmal Mohan N
 
Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)srigi
 
Use groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projectsUse groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projectsFátima Casaú Pérez
 
Gluecon 2014 - Bringing Node.js to the JVM
Gluecon 2014 - Bringing Node.js to the JVMGluecon 2014 - Bringing Node.js to the JVM
Gluecon 2014 - Bringing Node.js to the JVMJeremy Whitlock
 
The Saga of JavaScript and TypeScript: Part 1
The Saga of JavaScript and TypeScript: Part 1The Saga of JavaScript and TypeScript: Part 1
The Saga of JavaScript and TypeScript: Part 1Haci Murat Yaman
 
Php[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for BeginnersPhp[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for BeginnersAdam Englander
 
There is something about JavaScript - Choose Forum 2014
There is something about JavaScript - Choose Forum 2014There is something about JavaScript - Choose Forum 2014
There is something about JavaScript - Choose Forum 2014jbandi
 
Desarrollo multiplataforma con kotlin | UPV 2018
Desarrollo multiplataforma con kotlin  | UPV 2018Desarrollo multiplataforma con kotlin  | UPV 2018
Desarrollo multiplataforma con kotlin | UPV 2018Víctor Bolinches
 

La actualidad más candente (20)

Venkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In GroovyVenkat Subramaniam Building DSLs In Groovy
Venkat Subramaniam Building DSLs In Groovy
 
Golang
GolangGolang
Golang
 
JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!JavaCro 2016 - From Java to Groovy: Adventure Time!
JavaCro 2016 - From Java to Groovy: Adventure Time!
 
Pluggable web app using Angular (Odessa JS conf)
Pluggable web app using Angular (Odessa JS conf)Pluggable web app using Angular (Odessa JS conf)
Pluggable web app using Angular (Odessa JS conf)
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Web Development: Making it the right way
Web Development: Making it the right wayWeb Development: Making it the right way
Web Development: Making it the right way
 
Quick Review of Desktop and Native Apps using Javascript
Quick Review of Desktop and Native Apps using JavascriptQuick Review of Desktop and Native Apps using Javascript
Quick Review of Desktop and Native Apps using Javascript
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Intro to Crystal Programming Language
Intro to Crystal Programming LanguageIntro to Crystal Programming Language
Intro to Crystal Programming Language
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)Webpack & EcmaScript 6 (Webelement #32)
Webpack & EcmaScript 6 (Webelement #32)
 
Scala vs ruby
Scala vs rubyScala vs ruby
Scala vs ruby
 
Kotlin introduction
Kotlin introductionKotlin introduction
Kotlin introduction
 
Crystal
CrystalCrystal
Crystal
 
Use groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projectsUse groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projects
 
Gluecon 2014 - Bringing Node.js to the JVM
Gluecon 2014 - Bringing Node.js to the JVMGluecon 2014 - Bringing Node.js to the JVM
Gluecon 2014 - Bringing Node.js to the JVM
 
The Saga of JavaScript and TypeScript: Part 1
The Saga of JavaScript and TypeScript: Part 1The Saga of JavaScript and TypeScript: Part 1
The Saga of JavaScript and TypeScript: Part 1
 
Php[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for BeginnersPhp[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for Beginners
 
There is something about JavaScript - Choose Forum 2014
There is something about JavaScript - Choose Forum 2014There is something about JavaScript - Choose Forum 2014
There is something about JavaScript - Choose Forum 2014
 
Desarrollo multiplataforma con kotlin | UPV 2018
Desarrollo multiplataforma con kotlin  | UPV 2018Desarrollo multiplataforma con kotlin  | UPV 2018
Desarrollo multiplataforma con kotlin | UPV 2018
 

Destacado

GKAC 2014 Nov. - 그루비로 안드로이드 앱 개발하기
GKAC 2014 Nov. - 그루비로 안드로이드 앱 개발하기GKAC 2014 Nov. - 그루비로 안드로이드 앱 개발하기
GKAC 2014 Nov. - 그루비로 안드로이드 앱 개발하기GDG Korea
 
무식하게 배우는 gradle
무식하게 배우는 gradle무식하게 배우는 gradle
무식하게 배우는 gradleJi Heon Kim
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonSiddhi
 
서유럽 여행기 0820
서유럽 여행기 0820서유럽 여행기 0820
서유럽 여행기 0820Seeyoung Chang
 
Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기Hwang Sun Oh Kelly
 
gradle로 안드로이드 앱 빌드하기
gradle로 안드로이드 앱 빌드하기gradle로 안드로이드 앱 빌드하기
gradle로 안드로이드 앱 빌드하기Manjong Han
 
알파희 - PyPy/RPython으로 20배 빨라지는 아희 JIT 인터프리터
알파희 - PyPy/RPython으로 20배 빨라지는 아희 JIT 인터프리터알파희 - PyPy/RPython으로 20배 빨라지는 아희 JIT 인터프리터
알파희 - PyPy/RPython으로 20배 빨라지는 아희 JIT 인터프리터YunWon Jeong
 
AWS로 사용자 천만명 서비스 만들기 - 윤석찬 (AWS 테크에반젤리스트) :: AWS 웨비나 시리즈 2015
AWS로 사용자 천만명 서비스 만들기 - 윤석찬 (AWS 테크에반젤리스트) :: AWS 웨비나 시리즈 2015AWS로 사용자 천만명 서비스 만들기 - 윤석찬 (AWS 테크에반젤리스트) :: AWS 웨비나 시리즈 2015
AWS로 사용자 천만명 서비스 만들기 - 윤석찬 (AWS 테크에반젤리스트) :: AWS 웨비나 시리즈 2015Amazon Web Services Korea
 

Destacado (8)

GKAC 2014 Nov. - 그루비로 안드로이드 앱 개발하기
GKAC 2014 Nov. - 그루비로 안드로이드 앱 개발하기GKAC 2014 Nov. - 그루비로 안드로이드 앱 개발하기
GKAC 2014 Nov. - 그루비로 안드로이드 앱 개발하기
 
무식하게 배우는 gradle
무식하게 배우는 gradle무식하게 배우는 gradle
무식하게 배우는 gradle
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
서유럽 여행기 0820
서유럽 여행기 0820서유럽 여행기 0820
서유럽 여행기 0820
 
Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기Apache 핵심 프로젝트 camel 엿보기
Apache 핵심 프로젝트 camel 엿보기
 
gradle로 안드로이드 앱 빌드하기
gradle로 안드로이드 앱 빌드하기gradle로 안드로이드 앱 빌드하기
gradle로 안드로이드 앱 빌드하기
 
알파희 - PyPy/RPython으로 20배 빨라지는 아희 JIT 인터프리터
알파희 - PyPy/RPython으로 20배 빨라지는 아희 JIT 인터프리터알파희 - PyPy/RPython으로 20배 빨라지는 아희 JIT 인터프리터
알파희 - PyPy/RPython으로 20배 빨라지는 아희 JIT 인터프리터
 
AWS로 사용자 천만명 서비스 만들기 - 윤석찬 (AWS 테크에반젤리스트) :: AWS 웨비나 시리즈 2015
AWS로 사용자 천만명 서비스 만들기 - 윤석찬 (AWS 테크에반젤리스트) :: AWS 웨비나 시리즈 2015AWS로 사용자 천만명 서비스 만들기 - 윤석찬 (AWS 테크에반젤리스트) :: AWS 웨비나 시리즈 2015
AWS로 사용자 천만명 서비스 만들기 - 윤석찬 (AWS 테크에반젤리스트) :: AWS 웨비나 시리즈 2015
 

Similar a Dsl로 만나는 groovy

Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finessemzgubin
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGuillaume Laforge
 
Groovy Up Your Code
Groovy Up Your CodeGroovy Up Your Code
Groovy Up Your CodePaulo Traça
 
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
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails IntroductionEric Weimer
 
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGuillaume Laforge
 
Embedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationEmbedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationPaolo Predonzani
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mrubyHiroshi SHIBATA
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James NelsonGWTcon
 
Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVMelliando dias
 
Groovy and Grails intro
Groovy and Grails introGroovy and Grails intro
Groovy and Grails introMiguel Pastor
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the CloudJim Driscoll
 

Similar a Dsl로 만나는 groovy (20)

Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finesse
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
getting-your-groovy-on
getting-your-groovy-ongetting-your-groovy-on
getting-your-groovy-on
 
Groovy Up Your Code
Groovy Up Your CodeGroovy Up Your Code
Groovy Up Your Code
 
Grails 101
Grails 101Grails 101
Grails 101
 
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
 
Grooscript greach
Grooscript greachGrooscript greach
Grooscript greach
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
 
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific Languages
 
Embedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationEmbedding Groovy in a Java Application
Embedding Groovy in a Java Application
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVM
 
Groovy and Grails intro
Groovy and Grails introGroovy and Grails intro
Groovy and Grails intro
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the Cloud
 
Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Último (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Dsl로 만나는 groovy

  • 2. DSL •DSLR? DSL? A domain-specific language (DSL) is a computer language specialized to a particular application domain. http://en.wikipedia.org/wiki/Domain-specific_language http://www.aladin.co.kr/shop/wproduct.aspx?ISBN=8991268994 •DSL <-> GPL(General Purpose Language) •DSL = Mini Languages •DSL Example => XML, HTML, CSS, SQL •Groovy로 해석되는 DSL – 각종 Builder, GORM, gradle, Grails
  • 4. Groovy Builder DSL – XML writer = new StringWriter() builder = new groovy.xml.MarkupBuilder(writer) builder.numbers { description 'Squares and factors of 10..15' for (i in 10..15) { number (value: i, square: i*i) { //#1 for ( j in 2..<i) { if (i % j == 0) { factor (value: j) //#2 } } } } } println writer http://groovyconsole.appspot.com/
  • 5. Groovy Builder DSL - HTML def writer = new StringWriter() def html = new groovy.xml.MarkupBuilder(writer) html.html { head { title 'Constructed by MarkupBuilder' } body { h1 'What can I do with MarkupBuilder?' form (action:'whatever') { for (line in [ 'Produce HTML', 'Produce XML', 'Have some fun' ]){ input(type:'checkbox',checked:'checked', id:line, '') label(for:line, line) br('') } } } } println writer
  • 6. GORM – DSL • ORM DSL – Mapping • Table, Column mapping • Relational mapping – ORM관련 설정 • • • • Cache 전략 Custom ID 전략 Composite Primary Keys Index 설정 – http://grails.org/doc/latest/guide/single.html#ormdsl • Query DSL – Basic Query • list, get, getAll – Dynamic Finders • findByXXX – – Book.findByTitle(„정글만리‟), findByTitleLike(„%정글‟) http://grails.org/doc/latest/ref/Domain%20Classes/findBy.html
  • 7. Groovy로 만든 한글 DSL Object.metaClass.을 = Object.metaClass.를 = Object.metaClass.의 = { clos -> clos(delegate) } 먼저 = { it } 표시하라 = { println it } 제곱근 = { Math.sqrt(it) } 먼저 100 의 제곱근 을 표시하라 먼저(100).의(제곱근).을(표시하라) 출처: http://it.gilbird.com/textyle/8318
  • 8. Groovy는 왜 DSL에 강한가? • Dynamic Language – Dynamic Type num = 10; str = “20” assert num instanceof Integer assert str instanceof String – Closure • Caller에게 양보하기 – MOP(Meta Class, Expando Class) • 요술상자, 아메바 – Groovy‟s chain method calls (GEP 3) • 괄호 빼기 먼저 100 의 제곱근 을 표시하라 먼저(100).의(제곱근).을(표시하라) • JVM 기반 – Groovy는 결국 Java Class로 컴파일 – 거의 95%이상 Java와 동일하게 코딩 가능 – Java와 Groovy의 혼용
  • 9. Groovy MOP • MOP(Meta Object Protocol) – MetaObjectProtocol • http://en.wikipedia.org/wiki/Metaobject • MetaClass, ExpandoMetaClass http://mrhaki.blogspot.kr/2009/10/groovy-goodness-expando-as-dynamic-bean.html – 요술을 부리는 MOP Hooks • invokeMethod, methodMissing, get/setProperty, propertyMissing
  • 11. MOP Hooks - invokeMethod import org.codehaus.groovy.runtime.StringBufferWriter import org.codehaus.groovy.runtime.InvokerHelper class Traceable implements GroovyInterceptable { Writer writer = new PrintWriter(System.out) private int indent = 0 Object invokeMethod(String name, Object args){ writer.write("n" + ' '*indent + "before method '$name'") writer.flush() indent++ def metaClass = InvokerHelper.getMetaClass(this) def result = metaClass.invokeMethod(this, name, args) indent-writer.write("n" + ' '*indent + "after method '$name'") writer.flush() return result } } class Whatever extends Traceable { int outer(){ return inner() } int inner(){ return 1 } } def log = new StringBuffer() def traceMe = new Whatever(writer: new StringBufferWriter(log)) assert 1 == traceMe.outer() println log
  • 13. MOP Hooks – methodMissing class GORM { } def dynamicMethods = [...] // an array of dynamic methods that use regex def methodMissing(String name, args) { def method = dynamicMethods.find { it.match(name) } if(method) { GORM.metaClass."$name" = { Object[] varArgs -> method.invoke(delegate, name, varArgs) } return method.invoke(delegate,name, args) } else throw new MissingMethodException(name, delegate, args) } http://groovy.codehaus.org/Using+methodMissing+and+propertyMissing
  • 14. Groovy Closure def lineFile = new File(getClass().getResource("numbers.txt").getPath()) def sumValue = 0, multiflyValue = 1, concateValue = '' lineFile.eachLine { sumValue += Integer.parseInt(it) multiflyValue *= Integer.parseInt(it) concateValue += it } assert sumValue == 10 assert multiflyValue == 24 assert concateValue == '1234'
  • 15. 한국어 DSL로 돌아와서 Object.metaClass.을 = Object.metaClass.를 = Object.metaClass.의 = { clos -> clos(delegate) } 먼저 = { it } 표시하라 = { println it } 제곱근 = { Math.sqrt(it) } 먼저 100 의 제곱근 을 표시하라 먼저(100).의(제곱근).을(표시하라) 100.제곱근 을 표시하라 출처: http://it.gilbird.com/textyle/8318
  • 16. 관련 자료 • http://notes.3kbo.com/groovy-dsls • http://en.wikipedia.org/wiki/Domainspecific_language • DSL 번역본 • 프로그래밍 그루비 • 한국어 DSL • Groovy for Domain-Specific Languages • http://en.wikipedia.org/wiki/Metaobject • http://groovy.codehaus.org/api/overviewsummary.html • Groovy Grails 의 좋은 점 • ★ Groovy