Groovy 2.0 introduces several new features including command chains that allow dropping dots and parentheses when chaining method calls to write more readable DSL-style code. Other improvements include performance enhancements, built-in JSON support, and continued work on static type checking and static compilation.
Groovy update - S2GForum London 2011 - Guillaume LaforgeGuillaume Laforge
Groovy Update: what's new in 1.8 and what's coming in 1.9
The Groovy Development team is releasing Groovy 1.8, and this session will cover the new features including improved support for advanced and readable Domain-Specific Languages thanks to Groovy 1.8's "Extended Command Expressions", new performance improvements in the area of integer arithmetics, built-in support for parsing and producing JSON payloads, new AST transformations and now GPars come already bundled.
Ten common mistakes made with Functional Java JBCNConf18Brian Vermeer
Slides from my talk "Ten common mistakes made with Functional Java" @ JBCNConf 2018 Barcelona.
Beware that the slides are just here as a reference to people who attended this particular version of the talk. Please do not make assumptions purely from the slides alone ... there is a story with it ...really ;)
Groovy update - S2GForum London 2011 - Guillaume LaforgeGuillaume Laforge
Groovy Update: what's new in 1.8 and what's coming in 1.9
The Groovy Development team is releasing Groovy 1.8, and this session will cover the new features including improved support for advanced and readable Domain-Specific Languages thanks to Groovy 1.8's "Extended Command Expressions", new performance improvements in the area of integer arithmetics, built-in support for parsing and producing JSON payloads, new AST transformations and now GPars come already bundled.
Ten common mistakes made with Functional Java JBCNConf18Brian Vermeer
Slides from my talk "Ten common mistakes made with Functional Java" @ JBCNConf 2018 Barcelona.
Beware that the slides are just here as a reference to people who attended this particular version of the talk. Please do not make assumptions purely from the slides alone ... there is a story with it ...really ;)
Demos created for public lecture in VarnaLab (02 October 2013)
Github Demos : https://github.com/dimitardanailov/coffeescript-intro
Agenda :
Introduction
Installing CoffeeScript
Using CoffeeScript Files
Learning the Core Functionality
Data Types
Comments and Functions
Operators
Control Structures
Loops and Comprehensions
Scope and Context
Stirring in Advanced Concepts
Object Prototypes
CoffeeScript Classes
Heregexes
Using CoffeeScript in the Browser
Start with version control and experiments management in machine learningMikhail Rozhkov
How to manage complexity and reproducibility of Machine Learning projects? What requirements and tools? How to apply in your company and projects? Let's start with data and model version control! Review Data Version Control (DVC), MLFlow and other tools
Fort de ses 1.7 millions de téléchargements l'an passé, Groovy continue son bonhomme de chemin en tête parmi les langages de programmation alternatifs pour la JVM.
Groovy 2.0, sorti l'an passé, introduisait dans son offre de la modularité, le support de JDK 7 au niveau syntaxique avec "Project Coin" autant qu'au niveau JVM avec l'utilisation d'"invoke dynamic", et proposait des fonctionnalités de typage et de compilation statique.
Groovy 2.1, quant à lui, s'appuie sur ces bases pour compléter le support d'"invoke dynamic" pour plus de performances. Il propose des améliorations permettant de documenter, d'aider les IDEs, et de vérifier statiquement les Domain-Specific Languages construits avec Groovy. Vous pourrez créer des méta-annotations regroupant d'autres annotations, pour éviter l'annotation "hell". Et enfin, vous irez encore plus loin dans la customisation du compilateur !
Accrochez votre ceinture, paré au décollage !
"Groovy 2.0 and beyond" presentation given at the Groovy/Grails eXchange conference.
Video can be seen here:
http://skillsmatter.com/podcast/groovy-grails/keynote-speech
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
Paul King, Andrew Eisenberg and Guillaume Laforge present about implementation of Domain-Specific Languages in Groovy, while at the SpringOne2GX 2012 conference in Washington DC.
Groovy DSLs - S2GForum London 2011 - Guillaume LaforgeGuillaume Laforge
Design Your Own Domain Specific Language
This talk examines how dynamic languages in general and Groovy in particular provide toos to help design programming languages that are closer of the natural language of the target subject matter expert. It offers many features that allow you to create embedded DSLs: Closures, compile-time and run-time metaprogramming, operator overloading, named arguments, a more concise and expressive syntax and more.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
UiPath Test Automation using UiPath Test Suite series, part 5DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 5. In this session, we will cover CI/CD with devops.
Topics covered:
CI/CD with in UiPath
End-to-end overview of CI/CD pipeline with Azure devops
Speaker:
Lyndsey Byblow, Test Suite Sales Engineer @ UiPath, Inc.
Climate Impact of Software Testing at Nordic Testing DaysKari Kakkonen
My slides at Nordic Testing Days 6.6.2024
Climate impact / sustainability of software testing discussed on the talk. ICT and testing must carry their part of global responsibility to help with the climat warming. We can minimize the carbon footprint but we can also have a carbon handprint, a positive impact on the climate. Quality characteristics can be added with sustainability, and then measured continuously. Test environments can be used less, and in smaller scale and on demand. Test techniques can be used in optimizing or minimizing number of tests. Test automation can be used to speed up testing.
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
Unlocking Productivity: Leveraging the Potential of Copilot in Microsoft 365, a presentation by Christoforos Vlachos, Senior Solutions Manager – Modern Workplace, Uni Systems
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
3. Guillaume Laforge
• Groovy Project Manager at VMware
•Initiator of the Grails framework
•Creator of the Gaelyk
and Caelyf toolkits
• Co-author of Groovy in Action
• Follow me on...
•My blog: http://glaforge.appspot.com
•Twitter: @glaforge
•Google+: http://gplus.to/glaforge
2
4. Cédric Champeau
• Past: Groovy contributor then committer
• Present: Groovy Core Developer at VMware
•bug fixes with main focus on static type checking
and static compilation
• Follow me on...
•My blog: http://jroller.com/melix
•Twitter: @cedricchampeau
•Google+: http://gplus.to/cchampeau
3
5. Agenda (1/2)
• What’s new in Groovy 1.8?
• Nicer DSLs with command chains
• Runtime performance improvements
• GPars bundled for taming your multicores
• Closure enhancements
• Builtin JSON support
• New AST transformations
4
6. Agenda (2/2)
• What’s cooking for Groovy 2.0?
• Modularity
• Alignments with JDK 7
• Project Coin (small language changes)
• Invoke Dynamic support
• Continued runtime performance improvements
• Static type checking
• Static compilation
5
7. Command chains
• A grammar improvement allowing you
to drop dots & parens
when chaining method calls
• an extended version of top-level statements like println
• Less dots, less parens allow you to
•write more readable business rules
•in almost plain English sentences
•
(or any language, of course)
6
17. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
9
18. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
//
leverage
named-‐args
as
punctuation
9
19. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
9
20. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
//
closure
parameters
for
new
control
structures
9
21. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
9
22. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
//
zero-‐arg
methods
require
parens
9
23. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
//
zero-‐arg
methods
require
parens
select
all
unique()
from
names
9
24. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
//
zero-‐arg
methods
require
parens
select
all
unique()
from
names
//
possible
with
an
odd
number
of
terms
9
25. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
//
zero-‐arg
methods
require
parens
select
all
unique()
from
names
//
possible
with
an
odd
number
of
terms
take
3
cookies
9
26. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
(
).
(
).
(
)
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
//
zero-‐arg
methods
require
parens
select
all
unique()
from
names
//
possible
with
an
odd
number
of
terms
take
3
cookies
9
27. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
(
).
(
).
(
)
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
(
).
(
)
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
//
zero-‐arg
methods
require
parens
select
all
unique()
from
names
//
possible
with
an
odd
number
of
terms
take
3
cookies
9
28. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
(
).
(
).
(
)
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
(
).
(
)
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
(
).
(
).
(
)
//
zero-‐arg
methods
require
parens
select
all
unique()
from
names
//
possible
with
an
odd
number
of
terms
take
3
cookies
9
29. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
(
).
(
).
(
)
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
(
).
(
)
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
(
).
(
).
(
)
//
zero-‐arg
methods
require
parens
select
all
unique()
from
names
(
).
.
(
)
//
possible
with
an
odd
number
of
terms
take
3
cookies
9
30. Command chains
//
methods
with
multiple
arguments
(commas)
take
coffee
with
sugar,
milk
and
liquor
(
).
(
).
(
)
//
leverage
named-‐args
as
punctuation
check
that:
margarita
tastes
good
(
).
(
)
//
closure
parameters
for
new
control
structures
given
{}
when
{}
then
{}
(
).
(
).
(
)
//
zero-‐arg
methods
require
parens
select
all
unique()
from
names
(
).
.
(
)
//
possible
with
an
odd
number
of
terms
take
3
cookies
(
).
9
31. GPars bundled
• GPars is bundled in the Groovy distribution
• GPars covers a wide range of parallel
and concurrent paradigms
•actors, fork/join, map/filter/reduce, dataflow, agents
•parallel arrays, executors, STM, and more...
• And you can use it from plain Java as well!
10
32. Closure enhancements
• Closure annotation parameters
• Some more functional flavor
• composition
•
compose several closures into one single closure
• trampoline
• avoid stack overflow errors for recursive algorithms
• memoization
• remember the outcome of previous closure invocations
• currying improvements
11
33. Closure annotation parameters
@Retention(RetentionPolicy.RUNTIME)
@interface
Invariant
{
Class
value()
//
a
closure
class
}
{ @Invariant({
number
>=
0
})
class
Distance
{
float
number
String
unit
}
def
d
=
new
Distance(number:
10,
unit:
"meters")
def
anno
=
Distance.getAnnotation(Invariant)
def
check
=
anno.value().newInstance(d,
d)
assert
check(d)
12
34. Closure annotation parameters
@Retention(RetentionPolicy.RUNTIME)
@interface
Invariant
{
Class
value()
//
a
closure
class
}
{ @Invariant({
number
>=
0
})
class
Distance
{
float
number
Poor- man’s
GCon tracts
String
unit
}
def
d
=
new
Distance(number:
10,
unit:
"meters")
def
anno
=
Distance.getAnnotation(Invariant)
def
check
=
anno.value().newInstance(d,
d)
assert
check(d)
12
55. @Log
• Four different loggers can be injected
•@Log
•@Commons import
groovy.util.logging.*
•@Log4j
@Log
•@Slf4j class
Car
{
Car()
{
log.info
'Car
constructed'
• Possible to implement
}
}
your own strategy
def
c
=
new
Car()
19
56. @Log
• Four different loggers can be injected
•@Log
•@Commons import
groovy.util.logging.*
•@Log4j
@Log
•@Slf4j
Guarded
w/ an if
class
Car
{
Car()
{
log.info
'Car
constructed'
• Possible to implement
}
}
your own strategy
def
c
=
new
Car()
19
57. Controlling code execution
• Your application may run user’s code
•what if the code runs in infinite loops or for too long?
•what if the code consumes too many resources?
• 3 new transforms at your rescue
•@ThreadInterrupt: adds Thread#isInterrupted checks
so your executing thread stops when interrupted
•@TimedInterrupt: adds checks in method and
closure bodies to verify it’s run longer than expected
•@ConditionalInterrupt: adds checks with your own
conditional logic to break out from the user code
20
59. @ThreadInterrupt
@ThreadInterrupt
import
groovy.transform.ThreadInterrupt
while
(true)
{
{
if
(Thread.currentThread().isInterrupted())
throw
new
InterruptedException() }
//
eat
lots
of
CPU
}
21
33
60. @ToString
• Provides a default toString() method to your types
• Available annotation options
• includeNames, includeFields, includeSuper, excludes
import
groovy.transform.ToString
@ToString
class
Person
{
String
name
int
age
}
println
new
Person(name:
'Pete',
age:
15)
//
=>
Person(Pete,
15)
22
61. @EqualsAndHashCode
• Provides default implementations for equals() and
hashCode() methods
import
groovy.transform.EqualsAndHashCode
@EqualsAndHashCode
class
Coord
{
int
x,
y
}
def
c1
=
new
Coord(x:
20,
y:
5)
def
c2
=
new
Coord(x:
20,
y:
5)
assert
c1
==
c2
assert
c1.hashCode()
==
c2.hashCode()
23
62. @TupleConstructor
• Provides a «classical» constructor with all properties
• Several annotation parameter options available
import
groovy.transform.TupleConstructor
@TupleConstructor
class
Person
{
String
name
int
age
}
def
m
=
new
Person('Marion',
4)
assert
m.name
==
'Marion'
assert
m.age
==
4
24
63. @InheritConstructors
• Classes like Exception are painful when extended,
as all the base constructors should be replicated
class
CustomException
extends
Exception
{
CustomException()
{
super()
}
CustomException(String
msg)
{
super(msg)
}
CustomException(String
msg,
Throwable
t)
{
super(msg,
t)
}
CustomException(Throwable
t)
{
super(t)
}
}
25
64. @InheritConstructors
• Classes like Exception are painful when extended,
as all the base constructors should be replicated
import
groovy.transform.*
@InheritConstructors
class
CustomException
extends
Exception
{
CustomException()
{
super()
}
CustomException(String
msg)
{
super(msg)
}
CustomException(String
msg,
Throwable
t)
{
super(msg,
t)
}
CustomException(Throwable
t)
{
super(t)
}
}
25
65. Miscellaneous
• Compilation customizers
• Java 7 diamond operator
• Slashy and dollar slashy strings
• New GDK methods
• (G)String to Enum coercion
• Customizing the Groovysh prompt
• Executing remote scripts
26
66. Compilation customizers
• Ability to apply some customization to the Groovy
compilation process
• Three available customizers
•ImportCustomizer
•ASTTransformationCustomizer
•SecureASTCustomizer
• But you can implement your own
27
67. Imports customizer
def
configuration
=
new
CompilerConfiguration()
def
custo
=
new
ImportCustomizer()
custo.addStaticStar(Math.name)
configuration.addCompilationCustomizers(custo)
def
result
=
new
GroovyShell(configuration)
//
import
static
java.lang.Math.*
.evaluate("
cos
PI/3
")
28
70. Groovy 2.0
• A more modular Groovy
• Java 7 alignements: Project Coin
• binary literals
• underscore in literals
• multicatch
• JDK 7: InvokeDynamic
• Static type checking
• Static compilation
31
71. Groovy Modularity
• Groovy’s «all» JAR weighs in at 6 MB
• Nobody needs everything
• Template engine, Ant scripting, Swing UI building...
• Provide a smaller core
•and several smaller JARs per feature
• Provide hooks for setting up DGM methods, etc.
32
72. The new JARs
• A smaller groovy.jar: 3MB
• Modules
•console • sql
•docgenerator • swing
•groovydoc • servlet
•groovysh • templates
•ant • test
•bsf • testng
•jsr-223 • json
•jmx • xml
33
78. Binary literals
• We had decimal, octal and hexadecimal notations for
number literals
• We can now use binary representations too
int
x
=
0b10101111
assert
x
==
175
byte
aByte
=
0b00100001
assert
aByte
==
33
int
anInt
=
0b1010000101000101
assert
anInt
==
41285
38
79. Underscore in literals
• Now we can also add underscores
in number literals for more readability
long
creditCardNumber
=
1234_5678_9012_3456L
long
socialSecurityNumbers
=
999_99_9999L
float
monetaryAmount
=
12_345_132.12
long
hexBytes
=
0xFF_EC_DE_5E
long
hexWords
=
0xFFEC_DE5E
long
maxLong
=
0x7fff_ffff_ffff_ffffL
long
alsoMaxLong
=
9_223_372_036_854_775_807L
long
bytes
=
0b11010010_01101001_10010100_10010010
39
80. Multicatch
• One block for multiple exception caught
•rather than duplicating the block
try
{
/*
...
*/
}
catch(IOException
|
NullPointerException
e)
{
/*
one
block
to
treat
2
exceptions
*/
}
40
81. InvokeDynamic
• Groovy 2.0 supports JDK 7’s invokeDynamic
• compiler has a flag for compiling against JDK 7
• might use the invokeDynamic backport for < JDK 7
• Benefits
• more runtime performance!
•
at least as fast as current «dynamic» Groovy
•in the long run, will allow us to get rid of code!
•
call site caching, thanks to MethodHandles
•
metaclass registry, thanks to ClassValues
•
will let the JIT inline calls more easily
41
83. Static Type Checking
• Goal: make the Groovy compiler «grumpy»!
• and throw compilation errors (not at runtime)
• Not everybody needs dynamic features all the
time
• think Java libraries scripting
• Grumpy should...
• tell you about your method or variable typos
• complain if you call methods that don’t exist
• shout on assignments of wrong types
• infer the types of your variables
• figure out GDK methods
• etc...
43
84. Typos in a vars or methods
import
groovy.transform.TypeChecked
void
method()
{}
@TypeChecked
test()
{
//
Cannot
find
matching
method
metthhoood()
metthhoood()
def
name
=
"Guillaume"
//
variable
naamme
is
undeclared
println
naamme
}
44
85. Typos in a vars or methods
import
groovy.transform.TypeChecked
void
method()
{}
@TypeChecked
test()
{
//
Cannot
find
matching
method
metthhoood()
metthhoood()
def
name
=
"Guillaume" Compilation
//
variable
naamme
is
undeclared errors!
println
naamme
}
44
86. Typos in a vars or methods
Annotation can be at
import
groovy.transform.TypeChecked class or method level
void
method()
{}
@TypeChecked
test()
{
//
Cannot
find
matching
method
metthhoood()
metthhoood()
def
name
=
"Guillaume" Compilation
//
variable
naamme
is
undeclared errors!
println
naamme
}
44
87. Wrong assignments
//
cannot
assign
value
of
type...
to
variable...
int
x
=
new
Object()
Set
set
=
new
Object()
def
o
=
new
Object()
int
x
=
o
String[]
strings
=
['a','b','c']
int
str
=
strings[0]
//
cannot
find
matching
method
plus()
int
i
=
0
i
+=
'1'
45
88. Wrong assignments
//
cannot
assign
value
of
type...
to
variable...
int
x
=
new
Object()
Set
set
=
new
Object() Compilation
errors!
def
o
=
new
Object()
int
x
=
o
String[]
strings
=
['a','b','c']
int
str
=
strings[0]
//
cannot
find
matching
method
plus()
int
i
=
0
i
+=
'1'
45
89. Wrong return types
//
checks
if/else
branch
return
values
@TypeChecked
int
method()
{
if
(true)
{
'String'
}
else
{
42
}
}
//
works
for
switch/case
&
try/catch/finally
//
transparent
toString()
implied
@TypeChecked
String
greeting(String
name)
{
def
sb
=
new
StringBuilder()
sb
<<
"Hi
"
<<
name
}
46
90. Wrong return types
//
checks
if/else
branch
return
values
@TypeChecked
int
method()
{ Compilation
if
(true)
{
'String'
} error!
else
{
42
}
}
//
works
for
switch/case
&
try/catch/finally
//
transparent
toString()
implied
@TypeChecked
String
greeting(String
name)
{
def
sb
=
new
StringBuilder()
sb
<<
"Hi
"
<<
name
}
46
91. Type inference
@TypeChecked
test()
{
def
name
=
"
Guillaume
"
//
String
type
infered
(even
inside
GString)
println
"NAME
=
${name.toUpperCase()}"
//
Groovy
GDK
method
support
//
(GDK
operator
overloading
too)
println
name.trim()
int[]
numbers
=
[1,
2,
3]
//
Element
n
is
an
int
for
(int
n
in
numbers)
{
println
n
}
}
47
92. Statically checked & dyn meth
@TypeChecked
String
greeting(String
name)
{
//
call
method
with
dynamic
behavior
//
but
with
proper
signature
generateMarkup(name.toUpperCase())
}
//
usual
dynamic
behavior
String
generateMarkup(String
name)
{
def
sw
=
new
StringWriter()
new
MarkupBuilder(sw).html
{
body
{
div
name
}
}
sw.toString()
}
48
93. Instanceof checks
@TypeChecked
void
test(Object
val)
{
if
(val
instanceof
String)
{
println
val.toUpperCase()
}
else
if
(val
instanceof
Number)
{
println
"X"
*
val.intValue()
}
}
49
94. Instanceof checks
No need
@TypeChecked
for casts
void
test(Object
val)
{
if
(val
instanceof
String)
{
println
val.toUpperCase()
}
else
if
(val
instanceof
Number)
{
println
"X"
*
val.intValue()
}
}
49
95. Instanceof checks
No need
@TypeChecked
for casts
void
test(Object
val)
{
if
(val
instanceof
String)
{
println
val.toUpperCase()
}
else
if
(val
instanceof
Number)
{
println
"X"
*
val.intValue()
}
}
Can call String#multiply(int)
from the Groovy Development Kit
49
96. Lowest Upper Bound
• Represents the lowest «super» type classes
have in common
•may be virtual (aka «non-denotable»)
@TypeChecked
test()
{
//
an
integer
and
a
BigDecimal
return
[1234,
3.14]
}
50
97. Lowest Upper Bound
• Represents the lowest «super» type classes
have in common
•may be virtual (aka «non-denotable»)
@TypeChecked
test()
{
//
an
integer
and
a
BigDecimal
return
[1234,
3.14]
}
Inferred return type:
List<Number & Comparable>
50
98. Lowest Upper Bound
• Represents the lowest «super» type classes
have in common
•may be virtual (aka «non-denotable»)
@TypeChecked
test()
{
//
an
integer
and
a
BigDecimal
return
[1234,
3.14]
}
Inferred return type:
List<Number & Comparable>
50
99. Flow typing
• Static type checking shouldn’t complain even for bad coding
practicies which work without type checks
@TypeChecked
test()
{
def
var
=
123
//
inferred
type
is
int
int
x
=
var
//
var
is
an
int
var
=
"123"
//
assign
var
with
a
String
x
=
var.toInteger()
//
no
problem,
no
need
to
cast
var
=
123
x
=
var.toUpperCase()
//
error,
var
is
int!
}
51
100. Static checking vs dynamic
• Type checking works at compile-time
•adding @TypeChecked doesn’t change behavior
•
do not confuse with static compilation
• Most dynamic features cannot be type checked
•metaclass changes, categories
•dynamically bound variables (ex: script’s binding)
• However, compile-time metaprogramming works
•as long as proper type information is defined
52
104. Explicit type for closures
@TypeChecked
test()
{
["a",
"b",
"c"].collect
{
it.toUpperCase()
//
Not
OK
}
}
• A « Groovy Enhancement Proposal » to address the issue
54
105. Explicit type for closures
@TypeChecked
test()
{
["a",
"b",
"c"].collect
{
String
it
-‐>
it.toUpperCase()
//
OK,
it’s
a
String
}
}
• A « Groovy Enhancement Proposal » to address the issue
54
107. Closure shared variables
var assigned in the closure:
«shared closure variable»
@TypeChecked
test()
{
def
var
=
"abc"
def
cl
=
{
var
=
new
Date()
}
cl()
var.toUpperCase()
//
Not
OK!
}
55
108. Closure shared variables
var assigned in the closure:
«shared closure variable»
@TypeChecked
test()
{
Impossible to
def
var
=
"abc"
ensure the
def
cl
=
{
var
=
new
Date()
}
assignment
cl()
really happens
var.toUpperCase()
//
Not
OK!
}
55
109. Closure shared variables
var assigned in the closure:
«shared closure variable»
@TypeChecked
test()
{
Impossible to
def
var
=
"abc"
ensure the
def
cl
=
{
var
=
new
Date()
}
assignment
cl()
really happens
var.toUpperCase()
//
Not
OK!
}
Only methods of the most specific
compatible type (LUB) are
allowed by the type checker
55
110. Closure shared variables
class
A
{
void
foo()
{}
}
class
B
extends
A
{
void
bar()
{}
}
@TypeChecked
test()
{
def
var
=
new
A()
def
cl
=
{
var
=
new
B()
}
cl()
var.foo()
//
OK!
}
56
111. Closure shared variables
class
A
{
void
foo()
{}
}
class
B
extends
A
{
void
bar()
{}
}
@TypeChecked
test()
{
def
var
=
new
A()
def
cl
=
{
var
=
new
B()
}
cl()
var.foo()
//
OK!
}
var is at least
an instance of A
56
112. Static Compilation
• Given your Groovy code can be type checked...
we can as well compile it «statically»
• ie. generate the same byte code as javac
• Also interesting for those stuck in JDK < 7
to benefit from performance improvements
57
113. Advantages
• You gain:
• Type safety
• thanks to static type checking
• static compilation builds upon static type checking
• Faster code
• as close as possible to Java’s performance
• Code immune to «monkey patching»
• metaprogramming badly used can interfere with
framework code
• Smaller bytecode size
58
114. Disadvantages
• But you loose:
• Dynamic features
•metaclass changes, categories, etc.
• Dynamic method dispatch
•although as close as possible to «dynamic» Groovy
59
115. Statically compiled & dyn meth
@CompileStatic
String
greeting(String
name)
{
//
call
method
with
dynamic
behavior
//
but
with
proper
signature
generateMarkup(name.toUpperCase())
}
//
usual
dynamic
behavior
String
generateMarkup(String
name)
{
def
sw
=
new
StringWriter()
new
MarkupBuilder(sw).html
{
body
{
div
name
}
}
sw.toString()
}
60
116. What about performance?
• Comparisons between:
• Java
• Groovy static compilation (Groovy 2.0)
• Groovy with primitive optimizations (Groovy 1.8+)
• Groovy without optimizations (Groovy 1.7)
61
117. What about performance?
Pi (π) Binary
Fibonacci
quadrature trees
Java 188 ms 97 ms 3.6 s
Static
1.7 1.8 2.0
compilation
202 ms 101 ms 4.4 s
Primitive
optimizations
360 ms 111 ms 23.7 s
No prim.
optimizations
2590 ms 3220 ms 50.0 s
62
118. Summary
• Main themes of the Groovy 2.0 release
•Modularity
• Embark the JDK 7 enhancements
•Project Coin
•Invoke Dynamic
• Static aspects
• Static type checking
• Static compilation
63
120. Thank you!
e
eL aforg pment
Gu illaum ovy Develo
ro
He ad of G
om
gmail.c au
e@
glaforg rge Ch ampe itter
Email: @glafo rge édric ore Comm
: .t o/glafo m C
Twitter : http://gplus spot.co Groov
yC
gmail.c
om
+ pp
Google p://glaforge.a au@
hampe peau
tt ric.c
Blog: h ail: ced edriccham eau
Em
:@ c to/cchamp
Twitter : http://gplus. melix
+ /
Google p://jroller.com
tt
Blog: h
65
123. Groovy 1.8 AST Transform @Grab
1 // methods with multiple arguments (commas)
2 take coffee with sugar, milk and liquor
3
4 // leverage named-args as punctuation
5 check that: margarita tastes good
6
7 // closure parameters for new control structures
8 given {} when {} then {}
9
10 // zero-arg methods require parens
11 select all unique() from names
12
13 // possible with an odd number of terms
14 take 3 cookies
124. Groovy 1.8 AST Transform @Grab
1 // methods with multiple arguments (commas)
2 take coffee with sugar, milk and liquor
3
4 // leverage named-args as punctuation
5 check that: margarita tastes good Need parens
6
7 // closure parameters for new control
there!
structures
8 given {} when {} then {}
9
10 // zero-arg methods require parens
11 select all unique() from names
12
13 // possible with an odd number of terms
14 take 3 cookies