SlideShare une entreprise Scribd logo
1  sur  156
1. Два клЕвых пацана на
сцене
2. Прикольные загадки
3. Вы голосуете за
правильный ответ
4. Мы швыряемся вещами
-3.abs()
(-3).abs()
int value = -3
value.abs()
println (-3).abs()
-3
Caught: java.lang.NullPointerException: Cannot invoke method abs() on null
object
java.lang.NullPointerException: Cannot invoke method abs() on null object
at AbsolutelyGroovy.run(AbsolutelyGroovy.groovy:7)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
println (-3).abs()
“Все проблемы в программировании
можно решить добавив пару скобок”
John McCarthy, изобретатель LISP
println ((-3).abs())
int value = -3
println value.abs()
boolean isPrime(def x) {
if (x == 2) return true
int limit = Math.sqrt(x) + 1
(2..limit).each {
if (x % it == 0) {
return false
}
}
true
}
println isPrime("4" as Double)
boolean isPrime(def x) {
if (x == 2) return true
int limit = Math.sqrt(x) + 1
(2..limit).each {
if (x % it == 0) {
return false
}
}
true
}
println isPrime("4" as Double)
boolean isPrime(def x) {
if (x == 2) return true
int limit = Math.sqrt(x) + 1
(2..limit).each {
if (x % it == 0) {
return false
}
}
true
}
println isPrime("4" as Double)
http://kousenit.wordpress.com/2014/04/18/responses-to-the-closure-of-no-return/
class Conference {def name; def year}
def gr = new Conference(name: 'Greach', year: 2014)
gr.each {println it}
List<Integer> list = [56, '9', 74]
def max = list.max { item ->
(item < 50) ? item : null
}
println max
List<Integer> list = [56, '9', 74]
def max = list.max { item ->
(item < 50) ? item : null
}
println max
>groovysh (('9' as Character) as Integer)
===> 57
List<Integer> list = [56, 57, 74]
def max = list.max { item ->
(item < 50) ? item : null
}
println max
List<Integer> list = [56, '9', 74]
def max = list.max { item ->
(item < 50) ? item : null
}
println max
def random = new Random()
def randomList = []
0..10.each {randomList << random.nextInt()}
assert randomList.max{ null } == randomList[0]
Closure ктоУбийца() {
{
'Мориарти.'
}
}
println ктоУбийца()
Closure ктоУбийца() {
{ ->
'Мориарти.'
}
}
Closure ктоУбийца() {
return {
'Мориарти.'
}
}
class CountDown { int counter = 10 }
CountDown finalCountDown() {
def countDown = new CountDown()
try {
countDown.counter = --countDown.counter
} catch (ignored) {
println "That will never happen."
countDown.counter = Integer.MIN_VALUE
} finally {
return countDown
}
}
println finalCountDown().counter
class CountDown { int counter = 10 }
CountDown finalCountDown() {
def countDown = new CountDown()
try {
countDown.counter = --countDown.counter
} catch (ignored) {
println "That will never happen."
countDown.counter = Integer.MIN_VALUE
} finally {
return countDown
}
}
println finalCountDown().counter
class CountDown { int counter = 10 }
CountDown finalCountDown() {
def countDown = new CountDown()
try {
countDown.counter = --countDown.counter
} catch (ignored) {
ignored.printStackTrace()
countDown.counter = Integer.MIN_VALUE
} finally {
return countDown
}
}
println finalCountDown().counter
org.codehaus.groovy.runtime.typehandling.GroovyCastException:
Cannot cast object '9' with class 'java.lang.Integer' to class 'CountDown’
-2147483648
class CountDown { int counter = 10 }
CountDown finalCountDown() {
def countDown = new CountDown()
try {
countDown.counter = --countDown.counter
} catch (ignored) {
println "That will never happen."
countDown.counter = Integer.MIN_VALUE
} finally {
return countDown
}
42
}
println finalCountDown().counter
class CountDown { int counter = 10 }
CountDown finalCountDown() {
def countDown = new CountDown()
try {
countDown.counter = --countDown.counter
} catch (ignored) {
println "That will never happen."
countDown.counter = Integer.MIN_VALUE
} finally {
return countDown
}
42
}
println finalCountDown().counter
def key = 'x'
def map = [key: 'treasure']
def value = map.get(key)
println value
def key = 'x'
def map = [key: 'treasure']
def value = map.get(key)
println value
1.def map = [(key): 'treasure']
2.map.put(key, 'treasure')
3.map[key] = 'treasure'
4.map." " = 'treasure'
def map = [2: 'treasure']
def key = 2
def value = map."$key"
println value
def map = [2: 'treasure']
def key = 2
def value = map."$key"
println value
def map = [2: 'treasure']
println map.keySet().first().class.name
java.lang.Integer
def key = 'x'
def map = ["${key}": 'treasure']
def value = map['x']
println value
def key = 'x'
def map = ["${key}": 'treasure']
def value = map['x']
println value
def map = ["${key}": 'treasure']
println map.keySet().first().class.name
org.codehaus.groovy.runtime.GStringImpl
def range = 1.0..10.0
assert range.contains(5.0)
println range.contains(5.6)
Iterator iterator = (1.0..10.0).iterator()
while (iterator.hasNext()) {
print "${iterator.next()} "
}
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
[0..9].each { println(it - 1) }
[0..9].each { println(it - 1) }
Это неправильные
скобки!
(0..9).each { println(it - 1) }
Другое дело!
[0, 2, 3, 4, 5, 6, 7, 8, 9]
List<Long> list = [1,2,3]
def now = new Date()
list << now
println list
List<Long> list = [1,2,3]
def now = new Date()
list << now
println list
List<Long> list = [1,2,3]
def now = new Date()
list << now
list << 'foo'
println list*.class.name
[java.lang.Long, java.lang.Long,
java.lang.Long, java.util.Date,
java.lang.String]
double value = 3
println "$value.14".isDouble()
double value = 3
println "$value.14".isDouble()
Легко!
class Invite {
int attending = 1
}
def invite = new Invite()
def attendees = (invite.attending) +1
println attendees
Это Андрей
Это Джигурда
class Invite {
int attending = 1
}
def invite = new Invite()
def attendees = (invite.attending) +1
println attendees
def attendees = (new Invite().attending) + 1
println attendees
def invite = new Invite()
def attendees = invite.attending +1
Как убрать скобки?!
def invite = new Invite()
def attendees = ((invite.attending)) +1
Наоборот добавить.
Скобки никогда нельзя
убирать!
class MrHyde {
def me() {
return this
}
}
class DrJekyll {
}
DrJekyll.mixin MrHyde
def drJekyll = new DrJekyll().me() as DrJekyll
def mrHide = new DrJekyll().me()
println "$drJekyll and $mrHide, are they the
same? ${(drJekyll.class).equals(mrHide.class)}"
class MrHyde {
def me() {
return this
}
}
class DrJekyll {
}
DrJekyll.mixin MrHyde
def drJekyll = new DrJekyll().me() as DrJekyll
def mrHide = new DrJekyll().me()
println "$drJekyll and $mrHide, are they the same?
${(drJekyll.class).equals(mrHide.class)}"
def x = int
println x
if ((x = long)) {
println x
}
if (x = boolean ) {
println x
}
def x = int
println x
if ((x = long)) {
println x
}
if (x = boolean ) {
println x
}
class VanHalen {
public static jump() {
"Here are the ${lyrics()}"
}
def methodMissing(String name, def args) {
'lyrics'
}
}
println VanHalen.jump()
class VanHalen {
public static jump() {
"Here are the ${lyrics()}"
}
def methodMissing(String name, def args) {
'lyrics'
}
}
println VanHalen.jump()
class VanHalen {
public static jump() {
"Here are the ${lyrics()}"
}
static $static_methodMissing(String name, def args) {
'lyrics'
}
}
println VanHalen.jump()
class VanHalen {
public jump() {
"Here are the ${lyrics()}"
}
def methodMissing(String name, def args) {
'lyrics'
}
}
println new VanHalen().jump()
def map = [metaClass: ‘frequency']
println "What's the $map.metaClass, Барух?"
map.metaClass
map.get('metaClass')
map.getMetaClass()
1. Пишите читабельный код
2. Комментируйте все трюки
3. Иногда это баг
4. Пользуйте static code
analysis - intellij IDEA!
5. Rtfm
6. Don’t code like my brother
Groovy puzzlers jug-moscow-part 2

Contenu connexe

Tendances

Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기Suyeol Jeon
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Suyeol Jeon
 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212Mahmoud Samir Fayed
 
Beautiful python - PyLadies
Beautiful python - PyLadiesBeautiful python - PyLadies
Beautiful python - PyLadiesAlicia Pérez
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPaweł Dawczak
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.Mike Fogus
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2osfameron
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureMike Fogus
 
Mongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is BrightMongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is Brightaaronheckmann
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184Mahmoud Samir Fayed
 
Functional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures editionFunctional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures editionosfameron
 

Tendances (20)

Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212
 
Beautiful python - PyLadies
Beautiful python - PyLadiesBeautiful python - PyLadies
Beautiful python - PyLadies
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of Clojure
 
Ricky Bobby's World
Ricky Bobby's WorldRicky Bobby's World
Ricky Bobby's World
 
Mongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is BrightMongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is Bright
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184
 
Functional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures editionFunctional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures edition
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Intro
IntroIntro
Intro
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 

Similaire à Groovy puzzlers jug-moscow-part 2

The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsBaruch Sadogursky
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)GroovyPuzzlers
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objectsHusain Dalal
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdfkesav24
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
Lecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteLecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteDirkjan Bussink
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfJkPoppy
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala LanguageAshal aka JOKER
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of AtrocityMichael Pirnat
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...Revolution Analytics
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 

Similaire à Groovy puzzlers jug-moscow-part 2 (20)

The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)
 
Monadologie
MonadologieMonadologie
Monadologie
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
Lecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteLecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of Twente
 
Clojure入門
Clojure入門Clojure入門
Clojure入門
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdf
 
ddd+scala
ddd+scaladdd+scala
ddd+scala
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language
 
Exhibition of Atrocity
Exhibition of AtrocityExhibition of Atrocity
Exhibition of Atrocity
 
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
R + Hadoop = Big Data Analytics. How Revolution Analytics' RHadoop Project Al...
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 

Plus de Evgeny Borisov

Plus de Evgeny Borisov (10)

Java 8 puzzlers
Java 8 puzzlersJava 8 puzzlers
Java 8 puzzlers
 
Spring puzzlers 2
Spring puzzlers 2Spring puzzlers 2
Spring puzzlers 2
 
мифы о спарке
мифы о спарке мифы о спарке
мифы о спарке
 
Spring puzzlers
Spring puzzlersSpring puzzlers
Spring puzzlers
 
Spring data jee conf
Spring data jee confSpring data jee conf
Spring data jee conf
 
Groovy jug-moscow-part 1
Groovy jug-moscow-part 1Groovy jug-moscow-part 1
Groovy jug-moscow-part 1
 
Spock
SpockSpock
Spock
 
Spring the ripper
Spring the ripperSpring the ripper
Spring the ripper
 
Javaone 2013 moscow gradle english
Javaone 2013 moscow gradle   englishJavaone 2013 moscow gradle   english
Javaone 2013 moscow gradle english
 
Javaone 2013 moscow gradle
Javaone 2013 moscow gradleJavaone 2013 moscow gradle
Javaone 2013 moscow gradle
 

Dernier

Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfakankshagupta7348026
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxNikitaBankoti2
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Hasting Chen
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrsaastr
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...NETWAYS
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...Sheetaleventcompany
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 

Dernier (20)

Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdf
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 

Groovy puzzlers jug-moscow-part 2

  • 1.
  • 2.
  • 3. 1. Два клЕвых пацана на сцене 2. Прикольные загадки 3. Вы голосуете за правильный ответ 4. Мы швыряемся вещами
  • 4.
  • 5.
  • 6.
  • 7.
  • 9.
  • 10. (-3).abs() int value = -3 value.abs()
  • 11.
  • 13.
  • 14.
  • 15. -3 Caught: java.lang.NullPointerException: Cannot invoke method abs() on null object java.lang.NullPointerException: Cannot invoke method abs() on null object at AbsolutelyGroovy.run(AbsolutelyGroovy.groovy:7) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) println (-3).abs()
  • 16. “Все проблемы в программировании можно решить добавив пару скобок” John McCarthy, изобретатель LISP
  • 17. println ((-3).abs()) int value = -3 println value.abs()
  • 18.
  • 19. boolean isPrime(def x) { if (x == 2) return true int limit = Math.sqrt(x) + 1 (2..limit).each { if (x % it == 0) { return false } } true } println isPrime("4" as Double)
  • 20.
  • 21. boolean isPrime(def x) { if (x == 2) return true int limit = Math.sqrt(x) + 1 (2..limit).each { if (x % it == 0) { return false } } true } println isPrime("4" as Double)
  • 22. boolean isPrime(def x) { if (x == 2) return true int limit = Math.sqrt(x) + 1 (2..limit).each { if (x % it == 0) { return false } } true } println isPrime("4" as Double)
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 30.
  • 31. class Conference {def name; def year} def gr = new Conference(name: 'Greach', year: 2014) gr.each {println it}
  • 32.
  • 33.
  • 34.
  • 35. List<Integer> list = [56, '9', 74] def max = list.max { item -> (item < 50) ? item : null } println max
  • 36. List<Integer> list = [56, '9', 74] def max = list.max { item -> (item < 50) ? item : null } println max
  • 37. >groovysh (('9' as Character) as Integer) ===> 57
  • 38. List<Integer> list = [56, 57, 74] def max = list.max { item -> (item < 50) ? item : null } println max
  • 39.
  • 40. List<Integer> list = [56, '9', 74] def max = list.max { item -> (item < 50) ? item : null } println max
  • 41.
  • 42. def random = new Random() def randomList = [] 0..10.each {randomList << random.nextInt()} assert randomList.max{ null } == randomList[0]
  • 43.
  • 44.
  • 46.
  • 47. Closure ктоУбийца() { { -> 'Мориарти.' } } Closure ктоУбийца() { return { 'Мориарти.' } }
  • 48.
  • 49. class CountDown { int counter = 10 } CountDown finalCountDown() { def countDown = new CountDown() try { countDown.counter = --countDown.counter } catch (ignored) { println "That will never happen." countDown.counter = Integer.MIN_VALUE } finally { return countDown } } println finalCountDown().counter
  • 50. class CountDown { int counter = 10 } CountDown finalCountDown() { def countDown = new CountDown() try { countDown.counter = --countDown.counter } catch (ignored) { println "That will never happen." countDown.counter = Integer.MIN_VALUE } finally { return countDown } } println finalCountDown().counter
  • 51.
  • 52. class CountDown { int counter = 10 } CountDown finalCountDown() { def countDown = new CountDown() try { countDown.counter = --countDown.counter } catch (ignored) { ignored.printStackTrace() countDown.counter = Integer.MIN_VALUE } finally { return countDown } } println finalCountDown().counter org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '9' with class 'java.lang.Integer' to class 'CountDown’ -2147483648
  • 53.
  • 54.
  • 55. class CountDown { int counter = 10 } CountDown finalCountDown() { def countDown = new CountDown() try { countDown.counter = --countDown.counter } catch (ignored) { println "That will never happen." countDown.counter = Integer.MIN_VALUE } finally { return countDown } 42 } println finalCountDown().counter
  • 56. class CountDown { int counter = 10 } CountDown finalCountDown() { def countDown = new CountDown() try { countDown.counter = --countDown.counter } catch (ignored) { println "That will never happen." countDown.counter = Integer.MIN_VALUE } finally { return countDown } 42 } println finalCountDown().counter
  • 57.
  • 58.
  • 59.
  • 60.
  • 61. def key = 'x' def map = [key: 'treasure'] def value = map.get(key) println value
  • 62. def key = 'x' def map = [key: 'treasure'] def value = map.get(key) println value
  • 63.
  • 64.
  • 65. 1.def map = [(key): 'treasure'] 2.map.put(key, 'treasure') 3.map[key] = 'treasure' 4.map." " = 'treasure'
  • 66.
  • 67. def map = [2: 'treasure'] def key = 2 def value = map."$key" println value
  • 68. def map = [2: 'treasure'] def key = 2 def value = map."$key" println value
  • 69.
  • 70. def map = [2: 'treasure'] println map.keySet().first().class.name java.lang.Integer
  • 71.
  • 72. def key = 'x' def map = ["${key}": 'treasure'] def value = map['x'] println value
  • 73. def key = 'x' def map = ["${key}": 'treasure'] def value = map['x'] println value
  • 74.
  • 75. def map = ["${key}": 'treasure'] println map.keySet().first().class.name org.codehaus.groovy.runtime.GStringImpl
  • 76.
  • 77. def range = 1.0..10.0 assert range.contains(5.0) println range.contains(5.6)
  • 78.
  • 79.
  • 80.
  • 81.
  • 82. Iterator iterator = (1.0..10.0).iterator() while (iterator.hasNext()) { print "${iterator.next()} " } 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
  • 83.
  • 84.
  • 85.
  • 86.
  • 88.
  • 89. [0..9].each { println(it - 1) } Это неправильные скобки!
  • 90. (0..9).each { println(it - 1) } Другое дело!
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96. [0, 2, 3, 4, 5, 6, 7, 8, 9]
  • 97.
  • 98. List<Long> list = [1,2,3] def now = new Date() list << now println list
  • 99. List<Long> list = [1,2,3] def now = new Date() list << now println list
  • 100.
  • 101.
  • 102.
  • 103.
  • 104. List<Long> list = [1,2,3] def now = new Date() list << now list << 'foo' println list*.class.name [java.lang.Long, java.lang.Long, java.lang.Long, java.util.Date, java.lang.String]
  • 105.
  • 106.
  • 107. double value = 3 println "$value.14".isDouble()
  • 108.
  • 109.
  • 110.
  • 111. double value = 3 println "$value.14".isDouble()
  • 112.
  • 113.
  • 114.
  • 116. class Invite { int attending = 1 } def invite = new Invite() def attendees = (invite.attending) +1 println attendees Это Андрей Это Джигурда
  • 117. class Invite { int attending = 1 } def invite = new Invite() def attendees = (invite.attending) +1 println attendees
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123. def attendees = (new Invite().attending) + 1 println attendees
  • 124. def invite = new Invite() def attendees = invite.attending +1 Как убрать скобки?!
  • 125. def invite = new Invite() def attendees = ((invite.attending)) +1 Наоборот добавить. Скобки никогда нельзя убирать!
  • 126.
  • 127. class MrHyde { def me() { return this } } class DrJekyll { } DrJekyll.mixin MrHyde def drJekyll = new DrJekyll().me() as DrJekyll def mrHide = new DrJekyll().me() println "$drJekyll and $mrHide, are they the same? ${(drJekyll.class).equals(mrHide.class)}"
  • 128. class MrHyde { def me() { return this } } class DrJekyll { } DrJekyll.mixin MrHyde def drJekyll = new DrJekyll().me() as DrJekyll def mrHide = new DrJekyll().me() println "$drJekyll and $mrHide, are they the same? ${(drJekyll.class).equals(mrHide.class)}"
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134. def x = int println x if ((x = long)) { println x } if (x = boolean ) { println x }
  • 135. def x = int println x if ((x = long)) { println x } if (x = boolean ) { println x }
  • 136.
  • 137.
  • 138.
  • 139.
  • 140. class VanHalen { public static jump() { "Here are the ${lyrics()}" } def methodMissing(String name, def args) { 'lyrics' } } println VanHalen.jump()
  • 141. class VanHalen { public static jump() { "Here are the ${lyrics()}" } def methodMissing(String name, def args) { 'lyrics' } } println VanHalen.jump()
  • 142.
  • 143.
  • 144.
  • 145.
  • 146. class VanHalen { public static jump() { "Here are the ${lyrics()}" } static $static_methodMissing(String name, def args) { 'lyrics' } } println VanHalen.jump()
  • 147. class VanHalen { public jump() { "Here are the ${lyrics()}" } def methodMissing(String name, def args) { 'lyrics' } } println new VanHalen().jump()
  • 148.
  • 149. def map = [metaClass: ‘frequency'] println "What's the $map.metaClass, Барух?"
  • 150.
  • 151.
  • 153.
  • 154.
  • 155. 1. Пишите читабельный код 2. Комментируйте все трюки 3. Иногда это баг 4. Пользуйте static code analysis - intellij IDEA! 5. Rtfm 6. Don’t code like my brother

Notes de l'éditeur

  1. CURRENT – FRED NEXT - FRED
  2. List<Integer> list = [56, '9', 74,23,25,20] def max = list.max { item -> (item < 50) ? item : null } println max Это ищет максимальный элемент в листе из тех, что меньше 50
  3. CURRENT – JB NEXT - FRED
  4. 1985
  5. CURRENT – FRED NEXT - JB
  6. CURRENT – FRED NEXT - JB
  7. CURRENT – FRED NEXT - JB
  8. CURRENT – FRED NEXT - JB
  9. CURRENT – FRED NEXT - JB
  10. CURRENT – FRED NEXT - JB
  11. CURRENT – FRED NEXT - JB
  12. CURRENT – FRED NEXT - JB
  13. CURRENT – FRED NEXT - JB
  14. CURRENT – FRED NEXT - JB
  15. CURRENT – FRED NEXT - JB
  16. CURRENT – FRED NEXT - JB
  17. CURRENT – FRED NEXT - JB
  18. CURRENT – FRED NEXT - JB
  19. CURRENT – FRED NEXT - JB
  20. CURRENT – FRED NEXT - JB
  21. CURRENT – FRED NEXT - JB
  22. CURRENT – FRED NEXT - JB
  23. CURRENT – FRED NEXT - JB
  24. CURRENT – FRED NEXT - JB
  25. CURRENT – FRED NEXT - JB
  26. CURRENT – JB NEXT - FRED
  27. CURRENT – JB NEXT - FRED
  28. CURRENT – JB NEXT - FRED
  29. CURRENT – JB NEXT - FRED
  30. CURRENT – JB NEXT - FRED
  31. CURRENT – JB NEXT - FRED
  32. CURRENT – JB NEXT - FRED
  33. CURRENT – JB NEXT - FRED
  34. CURRENT – JB NEXT - FRED
  35. CURRENT – FRED
  36. CURRENT – FRED
  37. CURRENT – FRED
  38. CURRENT – FRED
  39. CURRENT – FRED
  40. CURRENT – FRED
  41. CURRENT – FRED
  42. CURRENT – FRED
  43. CURRENT – FRED
  44. CURRENT – FRED
  45. CURRENT – FRED
  46. CURRENT – JB NEXT - FRED
  47. CURRENT – JB NEXT - FRED
  48. CURRENT – JB NEXT - FRED
  49. CURRENT – JB NEXT - FRED
  50. CURRENT – JB NEXT - FRED
  51. CURRENT – JB NEXT - FRED
  52. CURRENT – FRED NEXT - JB
  53. CURRENT – FRED NEXT - JB
  54. CURRENT – FRED NEXT - JB
  55. CURRENT – FRED NEXT - JB
  56. CURRENT – FRED NEXT - JB
  57. CURRENT – FRED NEXT - JB
  58. CURRENT – FRED NEXT - JB (1983)
  59. CURRENT – FRED NEXT - JB
  60. CURRENT – FRED NEXT - JB
  61. CURRENT – FRED NEXT - JB
  62. CURRENT – FRED NEXT - JB
  63. CURRENT – FRED NEXT - JB
  64. CURRENT – FRED NEXT - JB
  65. CURRENT – FRED NEXT - JB
  66. CURRENT – FRED NEXT - JB
  67. CURRENT – JB NEXT - FRED 1993
  68. CURRENT – JB NEXT - FRED
  69. CURRENT – JB NEXT - FRED
  70. CURRENT – JB NEXT - FRED
  71. CURRENT – JB NEXT - FRED
  72. CURRENT – JB NEXT - FRED