SlideShare uma empresa Scribd logo
1 de 64
Baixar para ler offline
Copyright © 2013 Russel Winder 1
Is Groovy Static or
Dynamic?
Russel Winder
email: russel@winder.org.uk
xmpp: russel@winder.org.uk
twitter: @russel_winder
web: http://www.russel.org.uk
Copyright © 2013 Russel Winder 2
?
Copyright © 2013 Russel Winder 3
Prelude
Copyright © 2013 Russel Winder 4
Debate [d be t]ɪˈ ɪ
n
1. (Government, Politics & Diplomacy) a formal discussion, as in a legislative
body, in which opposing arguments are put forward
2. discussion or dispute
3. (Philosophy) the formal presentation and opposition of a specific motion,
followed by a vote
vb
1. to discuss (a motion), esp in a formal assembly
2. to deliberate upon (something) he debated with himself whether to go
[from Old French debatre to discuss, argue, from Latin battuere]
debater n
Collins English Dictionary – Complete and Unabridged © HarperCollins
Publishers 1991, 1994, 1998, 2000, 2003.
Copyright © 2013 Russel Winder 5
foment [f m nt]əˈ ɛ
vb (tr)
1. to encourage or instigate (trouble, discord, etc.); stir up
2. (Medicine) Med to apply heat and moisture to (a part of the body) to relieve
pain and inflammation
[from Late Latin f ment re, from Latin f mentum a poultice, ultimately fromō ā ō
fov re to foster]ē
fomentation [ f m n te n]ˌ əʊ ɛ ˈ ɪʃə n
fomenter n
Usage: Both foment and ferment can be used to talk about stirring up trouble:
he was accused of fomenting/fermenting unrest. Only ferment can be used
intransitively or as a noun: his anger continued to ferment (not foment); rural
areas were unaffected by the ferment in the cities
Collins English Dictionary – Complete and Unabridged © HarperCollins
Publishers 1991, 1994, 1998, 2000, 2003
Copyright © 2013 Russel Winder 6
ferment
n [ f m nt]ˈ ɜː ɛ
1. (Life Sciences & Allied Applications / Biochemistry) any agent or substance,
such as a bacterium, mould, yeast, or enzyme, that causes fermentation
2. (Life Sciences & Allied Applications / Biochemistry) another word for
fermentation
3. commotion; unrest
vb [f m nt]əˈ ɛ
1. (Life Sciences & Allied Applications / Biochemistry) to undergo or cause to
undergo fermentation
2. to stir up or seethe with excitement
[from Latin fermentum yeast, from ferv re to seethe]ē
fermentable adj
fermentability n
fermenter n
Usage: See at foment
Collins English Dictionary – Complete and Unabridged © HarperCollins
Publishers 1991, 1994, 1998, 2000, 2003
Copyright © 2013 Russel Winder 7
The intention of this session is to
foment debate.
Copyright © 2013 Russel Winder 8
Let the fomentation begin.
Copyright © 2013 Russel Winder 9
No not the fermentation.
Copyright © 2013 Russel Winder 10
Starting Point
Copyright © 2013 Russel Winder 11
2003
Groovy is created as the
dynamic symbiote to Java.
Copyright © 2013 Russel Winder 12
Dynamic languages have no typed variables.
Copyright © 2013 Russel Winder 13
static totallyDynamic(x, y) {
x * y
}
Copyright © 2013 Russel Winder 14
Copyright © 2013 Russel Winder 15
Duck typing:
The receiver of the message decides the
meaning of the message.
Copyright © 2013 Russel Winder 16
Operators are not messages to a
receiving object in Java…
Copyright © 2013 Russel Winder 17
…Java isn't really an object-oriented language.
Copyright © 2013 Russel Winder 18
Fortunately, Groovy decided to follow Smalltalk,
and have a meta-object protocol.
Copyright © 2013 Russel Winder 19
Groovy is truly object-oriented,
message passing is the operational semantic,
and all variables are references to objects.
Copyright © 2013 Russel Winder 20
x * y
transforms to
x.plus(y)
to realize message passing with method call.
Copyright © 2013 Russel Winder 21
Interesting Issue
Copyright © 2013 Russel Winder 22
Copyright © 2013 Russel Winder 23
Objects clearly have static types.
Copyright © 2013 Russel Winder 24
Java allows for despatch by signature,
i.e. methods can be overloaded.
Copyright © 2013 Russel Winder 25
Copyright © 2013 Russel Winder 26
Adding types to parameters is required
for despatch by signature.
Copyright © 2013 Russel Winder 27
static runtimeTyping(Number x, Number y) {
x * y
}
Copyright © 2013 Russel Winder 28
Groovy is an optionally typed language:
variables, not just function and method
parameters, may or may not be given a type.
Copyright © 2013 Russel Winder 29
Adding types works in harmony with
method overloading.
Copyright © 2013 Russel Winder 30
All type checking is at run time.
This is harmonious with duck typing.
Copyright © 2013 Russel Winder 31
Being up to date
Copyright © 2013 Russel Winder 32
2013
Groovy is the dynamic symbiote to Java,
and
Groovy can now be the static language
replacement for Java.
Copyright © 2013 Russel Winder 33
@TypeChecked
@CompileStatic
Copyright © 2013 Russel Winder 34
@TypeChecked
static staticTyping(x, y) {
x * y
}
Copyright © 2013 Russel Winder 35
Compile time interface conformance,
no duck typing.
Copyright © 2013 Russel Winder 36
✘✘
Copyright © 2013 Russel Winder 37
Groovy now has C++-style message passing.
Copyright © 2013 Russel Winder 38
@TypeChecked
static staticTyping(Number x, Number y) {
x * y
}
Copyright © 2013 Russel Winder 39
Enforce don't ask.
Copyright © 2013 Russel Winder 40
A totally different view of how computation
proceeds: a different computational model.
Copyright © 2013 Russel Winder 41
class ExpandoDynamic {
static void main(args) {
def x = new Expando()
x.multiply = { y -> x.data * y }
x.data = 'XX'
def y = 2
assert x * 2 == 'XXXX'
}
}
Copyright © 2013 Russel Winder 42
@TypeChecked
class ExpandoStatic {
static void main(args) {
def x = new Expando()
x.multiply = { y -> x.data * y }
x.data = 'XX'
def y = 2
assert x * 2 == 'XXXX'
}
}
Copyright © 2013 Russel Winder 43
Should a language support two disparate
computational models?
Copyright © 2013 Russel Winder 44
final class Thing {
final x
Thing(x) { this.x = x }
Thing multiply(Thing y) { new Thing(x * y.x) }
boolean equals(Thing y) { x == y.x }
boolean equals (Object y) { x == y }
String toString() { x.toString() }
}
x = new Thing('XX')
y = new Thing(2)
z = new Thing(2.0)
assert x * y == 'XXXX'
assert x * y == new Thing('XXXX')
assert x * z == 'XXXX'
assert x * z == new Thing('XXXX')
assert y * z == 4.0
assert y * z == new Thing(4.0)
assert z * y == 4.0
assert z * y == new Thing(4.0)
Copyright © 2013 Russel Winder 45
@TypeChecked
final class Thing {
final Integer x_i
final String x_s
Thing(Integer x) { this.x_i = x ; assert this.x_s == null }
Thing(String x) { this.x_s = x ; assert this.x_i == null }
Thing multiply(Thing y) {
if (x_i == null) { new Thing(StringGroovyMethods.multiply(x_s, (Number)y.x)) }
else { new Thing(x_i * y.x_i) }
}
Object getX() { x_i == null ? x_s : x_i }
boolean equals(Thing y) { x_i == null ? x_s == y.x_s : x_i == y.x_i }
boolean equals (Object y) { x == y }
String toString() { x.toString() }
}
x = new Thing('XX')
y = new Thing(2)
assert x * y == 'XXXX'
assert x * y == new Thing('XXXX')
Copyright © 2013 Russel Winder 46
Should a language do one thing well?
Copyright © 2013 Russel Winder 47
class Duck {
static main(args) {
def total = 1
def data = [2, 3]
try {
total += data.sum()
}
catch (MissingMethodException mme) {
total = 0
}
assert total == 6
}
}
Copyright © 2013 Russel Winder 48
@TypeChecked
class NotDuck {
static void main(String[] args) {
Integer total = 1
List data = [2, 3]
total += (Integer)data.sum()
assert total == 6
}
}
Copyright © 2013 Russel Winder 49
Should a language be all things…
Copyright © 2013 Russel Winder 50
Copyright © 2013 Russel Winder 51
…or should we embrace polyglot programming?
Copyright © 2013 Russel Winder 52
Groovy +
{
Java
Scala
Ceylon
Kotlin
Copyright © 2013 Russel Winder 53
Tooling and IDE support is a big issue.
Copyright © 2013 Russel Winder 54
Endnote
Copyright © 2013 Russel Winder 55
This is philosophizing.
Copyright © 2013 Russel Winder 56
Personal experience useful.
We are allowed to debate and (dis)agree.
Create a personal view.
Copyright © 2013 Russel Winder 57
What is really needed is some objective research.
Copyright © 2013 Russel Winder 58
Copyright © 2013 Russel Winder 59
Psychology of programming.
PPIG.
Copyright © 2013 Russel Winder 60
foment [f m nt]əˈ ɛ
vb (tr)
1. to encourage or instigate (trouble, discord, etc.); stir up
2. (Medicine) Med to apply heat and moisture to (a part of the body) to relieve
pain and inflammation
[from Late Latin f ment re, from Latin f mentum a poultice, ultimately fromō ā ō
fov re to foster]ē
fomentation [ f m n te n] nˌ əʊ ɛ ˈ ɪʃə
fomenter n
Usage: Both foment and ferment can be used to talk about stirring up trouble:
he was accused of fomenting/fermenting unrest. Only ferment can be used
intransitively or as a noun: his anger continued to ferment (not foment); rural
areas were unaffected by the ferment in the cities
Collins English Dictionary – Complete and Unabridged © HarperCollins
Publishers 1991, 1994, 1998, 2000, 2003
Copyright © 2013 Russel Winder 61
ferment
n [ f m nt]ˈ ɜː ɛ
1. (Life Sciences & Allied Applications / Biochemistry) any agent or substance,
such as a bacterium, mould, yeast, or enzyme, that causes fermentation
2. (Life Sciences & Allied Applications / Biochemistry) another word for
fermentation
3. commotion; unrest
vb [f m nt]əˈ ɛ
1. (Life Sciences & Allied Applications / Biochemistry) to undergo or cause to
undergo fermentation
2. to stir up or seethe with excitement
[from Latin fermentum yeast, from ferv re to seethe]ē
fermentable adj
fermentability n
fermenter n
Usage: See at foment
Collins English Dictionary – Complete and Unabridged © HarperCollins
Publishers 1991, 1994, 1998, 2000, 2003
Copyright © 2013 Russel Winder 62
?
Copyright © 2013 Russel Winder 63
Is Groovy Static or
Dynamic?
Russel Winder
email: russel@winder.org.uk
xmpp: russel@winder.org.uk
twitter: @russel_winder
web: http://www.russel.org.uk
Copyright © 2013 Russel Winder 64
Groovy is Static or Dynamic
Russel Winder
email: russel@winder.org.uk
xmpp: russel@winder.org.uk
twitter: @russel_winder
web: http://www.russel.org.uk

Mais conteúdo relacionado

Mais de Russel Winder

Mais de Russel Winder (20)

On Concurrency and Parallelism in the JVMverse
On Concurrency and Parallelism in the JVMverseOn Concurrency and Parallelism in the JVMverse
On Concurrency and Parallelism in the JVMverse
 
The Case for Kotlin and Ceylon
The Case for Kotlin and CeylonThe Case for Kotlin and Ceylon
The Case for Kotlin and Ceylon
 
On the Architectures of Microservices: the next layer
On the Architectures of Microservices: the next layerOn the Architectures of Microservices: the next layer
On the Architectures of Microservices: the next layer
 
Fast Python? Don't Bother
Fast Python? Don't BotherFast Python? Don't Bother
Fast Python? Don't Bother
 
Making Python computations fast
Making Python computations fastMaking Python computations fast
Making Python computations fast
 
Making Computations Execute Very Quickly
Making Computations Execute Very QuicklyMaking Computations Execute Very Quickly
Making Computations Execute Very Quickly
 
Java is Dead, Long Live Ceylon, Kotlin, etc
Java is Dead,  Long Live Ceylon, Kotlin, etcJava is Dead,  Long Live Ceylon, Kotlin, etc
Java is Dead, Long Live Ceylon, Kotlin, etc
 
Java is dead, long live Scala, Kotlin, Ceylon, etc.
Java is dead, long live Scala, Kotlin, Ceylon, etc.Java is dead, long live Scala, Kotlin, Ceylon, etc.
Java is dead, long live Scala, Kotlin, Ceylon, etc.
 
GPars 2014
GPars 2014GPars 2014
GPars 2014
 
Java is dead, long live Scala Kotlin Ceylon etc.
Java is dead, long live Scala Kotlin Ceylon etc.Java is dead, long live Scala Kotlin Ceylon etc.
Java is dead, long live Scala Kotlin Ceylon etc.
 
Dataflow: the concurrency/parallelism architecture you need
Dataflow: the concurrency/parallelism architecture you needDataflow: the concurrency/parallelism architecture you need
Dataflow: the concurrency/parallelism architecture you need
 
Is Groovy as fast as Java
Is Groovy as fast as JavaIs Groovy as fast as Java
Is Groovy as fast as Java
 
Who needs C++ when you have D and Go
Who needs C++ when you have D and GoWho needs C++ when you have D and Go
Who needs C++ when you have D and Go
 
Java 8: a New Beginning
Java 8: a New BeginningJava 8: a New Beginning
Java 8: a New Beginning
 
Why Go is an important programming language
Why Go is an important programming languageWhy Go is an important programming language
Why Go is an important programming language
 
GPars: Groovy Parallelism for Java
GPars: Groovy Parallelism for JavaGPars: Groovy Parallelism for Java
GPars: Groovy Parallelism for Java
 
GroovyFX: or how to program JavaFX easily
GroovyFX: or how to program JavaFX easily GroovyFX: or how to program JavaFX easily
GroovyFX: or how to program JavaFX easily
 
Switch to Python 3…now…immediately
Switch to Python 3…now…immediatelySwitch to Python 3…now…immediately
Switch to Python 3…now…immediately
 
GPars Workshop
GPars WorkshopGPars Workshop
GPars Workshop
 
Given Groovy Who Needs Java
Given Groovy Who Needs JavaGiven Groovy Who Needs Java
Given Groovy Who Needs Java
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
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
vu2urc
 
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
Earley Information Science
 

Último (20)

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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Is Groovy static or dynamic

  • 1. Copyright © 2013 Russel Winder 1 Is Groovy Static or Dynamic? Russel Winder email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder web: http://www.russel.org.uk
  • 2. Copyright © 2013 Russel Winder 2 ?
  • 3. Copyright © 2013 Russel Winder 3 Prelude
  • 4. Copyright © 2013 Russel Winder 4 Debate [d be t]ɪˈ ɪ n 1. (Government, Politics & Diplomacy) a formal discussion, as in a legislative body, in which opposing arguments are put forward 2. discussion or dispute 3. (Philosophy) the formal presentation and opposition of a specific motion, followed by a vote vb 1. to discuss (a motion), esp in a formal assembly 2. to deliberate upon (something) he debated with himself whether to go [from Old French debatre to discuss, argue, from Latin battuere] debater n Collins English Dictionary – Complete and Unabridged © HarperCollins Publishers 1991, 1994, 1998, 2000, 2003.
  • 5. Copyright © 2013 Russel Winder 5 foment [f m nt]əˈ ɛ vb (tr) 1. to encourage or instigate (trouble, discord, etc.); stir up 2. (Medicine) Med to apply heat and moisture to (a part of the body) to relieve pain and inflammation [from Late Latin f ment re, from Latin f mentum a poultice, ultimately fromō ā ō fov re to foster]ē fomentation [ f m n te n]ˌ əʊ ɛ ˈ ɪʃə n fomenter n Usage: Both foment and ferment can be used to talk about stirring up trouble: he was accused of fomenting/fermenting unrest. Only ferment can be used intransitively or as a noun: his anger continued to ferment (not foment); rural areas were unaffected by the ferment in the cities Collins English Dictionary – Complete and Unabridged © HarperCollins Publishers 1991, 1994, 1998, 2000, 2003
  • 6. Copyright © 2013 Russel Winder 6 ferment n [ f m nt]ˈ ɜː ɛ 1. (Life Sciences & Allied Applications / Biochemistry) any agent or substance, such as a bacterium, mould, yeast, or enzyme, that causes fermentation 2. (Life Sciences & Allied Applications / Biochemistry) another word for fermentation 3. commotion; unrest vb [f m nt]əˈ ɛ 1. (Life Sciences & Allied Applications / Biochemistry) to undergo or cause to undergo fermentation 2. to stir up or seethe with excitement [from Latin fermentum yeast, from ferv re to seethe]ē fermentable adj fermentability n fermenter n Usage: See at foment Collins English Dictionary – Complete and Unabridged © HarperCollins Publishers 1991, 1994, 1998, 2000, 2003
  • 7. Copyright © 2013 Russel Winder 7 The intention of this session is to foment debate.
  • 8. Copyright © 2013 Russel Winder 8 Let the fomentation begin.
  • 9. Copyright © 2013 Russel Winder 9 No not the fermentation.
  • 10. Copyright © 2013 Russel Winder 10 Starting Point
  • 11. Copyright © 2013 Russel Winder 11 2003 Groovy is created as the dynamic symbiote to Java.
  • 12. Copyright © 2013 Russel Winder 12 Dynamic languages have no typed variables.
  • 13. Copyright © 2013 Russel Winder 13 static totallyDynamic(x, y) { x * y }
  • 14. Copyright © 2013 Russel Winder 14
  • 15. Copyright © 2013 Russel Winder 15 Duck typing: The receiver of the message decides the meaning of the message.
  • 16. Copyright © 2013 Russel Winder 16 Operators are not messages to a receiving object in Java…
  • 17. Copyright © 2013 Russel Winder 17 …Java isn't really an object-oriented language.
  • 18. Copyright © 2013 Russel Winder 18 Fortunately, Groovy decided to follow Smalltalk, and have a meta-object protocol.
  • 19. Copyright © 2013 Russel Winder 19 Groovy is truly object-oriented, message passing is the operational semantic, and all variables are references to objects.
  • 20. Copyright © 2013 Russel Winder 20 x * y transforms to x.plus(y) to realize message passing with method call.
  • 21. Copyright © 2013 Russel Winder 21 Interesting Issue
  • 22. Copyright © 2013 Russel Winder 22
  • 23. Copyright © 2013 Russel Winder 23 Objects clearly have static types.
  • 24. Copyright © 2013 Russel Winder 24 Java allows for despatch by signature, i.e. methods can be overloaded.
  • 25. Copyright © 2013 Russel Winder 25
  • 26. Copyright © 2013 Russel Winder 26 Adding types to parameters is required for despatch by signature.
  • 27. Copyright © 2013 Russel Winder 27 static runtimeTyping(Number x, Number y) { x * y }
  • 28. Copyright © 2013 Russel Winder 28 Groovy is an optionally typed language: variables, not just function and method parameters, may or may not be given a type.
  • 29. Copyright © 2013 Russel Winder 29 Adding types works in harmony with method overloading.
  • 30. Copyright © 2013 Russel Winder 30 All type checking is at run time. This is harmonious with duck typing.
  • 31. Copyright © 2013 Russel Winder 31 Being up to date
  • 32. Copyright © 2013 Russel Winder 32 2013 Groovy is the dynamic symbiote to Java, and Groovy can now be the static language replacement for Java.
  • 33. Copyright © 2013 Russel Winder 33 @TypeChecked @CompileStatic
  • 34. Copyright © 2013 Russel Winder 34 @TypeChecked static staticTyping(x, y) { x * y }
  • 35. Copyright © 2013 Russel Winder 35 Compile time interface conformance, no duck typing.
  • 36. Copyright © 2013 Russel Winder 36 ✘✘
  • 37. Copyright © 2013 Russel Winder 37 Groovy now has C++-style message passing.
  • 38. Copyright © 2013 Russel Winder 38 @TypeChecked static staticTyping(Number x, Number y) { x * y }
  • 39. Copyright © 2013 Russel Winder 39 Enforce don't ask.
  • 40. Copyright © 2013 Russel Winder 40 A totally different view of how computation proceeds: a different computational model.
  • 41. Copyright © 2013 Russel Winder 41 class ExpandoDynamic { static void main(args) { def x = new Expando() x.multiply = { y -> x.data * y } x.data = 'XX' def y = 2 assert x * 2 == 'XXXX' } }
  • 42. Copyright © 2013 Russel Winder 42 @TypeChecked class ExpandoStatic { static void main(args) { def x = new Expando() x.multiply = { y -> x.data * y } x.data = 'XX' def y = 2 assert x * 2 == 'XXXX' } }
  • 43. Copyright © 2013 Russel Winder 43 Should a language support two disparate computational models?
  • 44. Copyright © 2013 Russel Winder 44 final class Thing { final x Thing(x) { this.x = x } Thing multiply(Thing y) { new Thing(x * y.x) } boolean equals(Thing y) { x == y.x } boolean equals (Object y) { x == y } String toString() { x.toString() } } x = new Thing('XX') y = new Thing(2) z = new Thing(2.0) assert x * y == 'XXXX' assert x * y == new Thing('XXXX') assert x * z == 'XXXX' assert x * z == new Thing('XXXX') assert y * z == 4.0 assert y * z == new Thing(4.0) assert z * y == 4.0 assert z * y == new Thing(4.0)
  • 45. Copyright © 2013 Russel Winder 45 @TypeChecked final class Thing { final Integer x_i final String x_s Thing(Integer x) { this.x_i = x ; assert this.x_s == null } Thing(String x) { this.x_s = x ; assert this.x_i == null } Thing multiply(Thing y) { if (x_i == null) { new Thing(StringGroovyMethods.multiply(x_s, (Number)y.x)) } else { new Thing(x_i * y.x_i) } } Object getX() { x_i == null ? x_s : x_i } boolean equals(Thing y) { x_i == null ? x_s == y.x_s : x_i == y.x_i } boolean equals (Object y) { x == y } String toString() { x.toString() } } x = new Thing('XX') y = new Thing(2) assert x * y == 'XXXX' assert x * y == new Thing('XXXX')
  • 46. Copyright © 2013 Russel Winder 46 Should a language do one thing well?
  • 47. Copyright © 2013 Russel Winder 47 class Duck { static main(args) { def total = 1 def data = [2, 3] try { total += data.sum() } catch (MissingMethodException mme) { total = 0 } assert total == 6 } }
  • 48. Copyright © 2013 Russel Winder 48 @TypeChecked class NotDuck { static void main(String[] args) { Integer total = 1 List data = [2, 3] total += (Integer)data.sum() assert total == 6 } }
  • 49. Copyright © 2013 Russel Winder 49 Should a language be all things…
  • 50. Copyright © 2013 Russel Winder 50
  • 51. Copyright © 2013 Russel Winder 51 …or should we embrace polyglot programming?
  • 52. Copyright © 2013 Russel Winder 52 Groovy + { Java Scala Ceylon Kotlin
  • 53. Copyright © 2013 Russel Winder 53 Tooling and IDE support is a big issue.
  • 54. Copyright © 2013 Russel Winder 54 Endnote
  • 55. Copyright © 2013 Russel Winder 55 This is philosophizing.
  • 56. Copyright © 2013 Russel Winder 56 Personal experience useful. We are allowed to debate and (dis)agree. Create a personal view.
  • 57. Copyright © 2013 Russel Winder 57 What is really needed is some objective research.
  • 58. Copyright © 2013 Russel Winder 58
  • 59. Copyright © 2013 Russel Winder 59 Psychology of programming. PPIG.
  • 60. Copyright © 2013 Russel Winder 60 foment [f m nt]əˈ ɛ vb (tr) 1. to encourage or instigate (trouble, discord, etc.); stir up 2. (Medicine) Med to apply heat and moisture to (a part of the body) to relieve pain and inflammation [from Late Latin f ment re, from Latin f mentum a poultice, ultimately fromō ā ō fov re to foster]ē fomentation [ f m n te n] nˌ əʊ ɛ ˈ ɪʃə fomenter n Usage: Both foment and ferment can be used to talk about stirring up trouble: he was accused of fomenting/fermenting unrest. Only ferment can be used intransitively or as a noun: his anger continued to ferment (not foment); rural areas were unaffected by the ferment in the cities Collins English Dictionary – Complete and Unabridged © HarperCollins Publishers 1991, 1994, 1998, 2000, 2003
  • 61. Copyright © 2013 Russel Winder 61 ferment n [ f m nt]ˈ ɜː ɛ 1. (Life Sciences & Allied Applications / Biochemistry) any agent or substance, such as a bacterium, mould, yeast, or enzyme, that causes fermentation 2. (Life Sciences & Allied Applications / Biochemistry) another word for fermentation 3. commotion; unrest vb [f m nt]əˈ ɛ 1. (Life Sciences & Allied Applications / Biochemistry) to undergo or cause to undergo fermentation 2. to stir up or seethe with excitement [from Latin fermentum yeast, from ferv re to seethe]ē fermentable adj fermentability n fermenter n Usage: See at foment Collins English Dictionary – Complete and Unabridged © HarperCollins Publishers 1991, 1994, 1998, 2000, 2003
  • 62. Copyright © 2013 Russel Winder 62 ?
  • 63. Copyright © 2013 Russel Winder 63 Is Groovy Static or Dynamic? Russel Winder email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder web: http://www.russel.org.uk
  • 64. Copyright © 2013 Russel Winder 64 Groovy is Static or Dynamic Russel Winder email: russel@winder.org.uk xmpp: russel@winder.org.uk twitter: @russel_winder web: http://www.russel.org.uk