eXo EC - Groovy Programming Language

hoatle 806 views 10 slides Aug 20, 2009
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

No description available for this slideshow.


Slide Content

Groovy Programing Language
Why this topic?
Agile web development with Grails
Apply better practice to our groovy templates
After this topic?
Web development with Grails
Develop Grails with Flex and deploy on Google App
Engine or Spring Source Cloud

Groovy Programming Language
What is Groovy?
Let's play with Groovy
Some basic differences from Java
Some new operators
Anything in Java but not in Groovy
Expert Groovy
Best practices

What is Groovy?
In 1995, Java changed the world
Now Java bloats with too many frameworks,
libs... → many organizations have to
consider Ruby, LAMP, .NET for more
productive and agile at lower costs
Groovy appeared in 2003 – promising more
complete and dynamic language for JVM
instead of Ruby, Python, or JavaScript
implementation for JVM.

Let's play with Groovy
Our famous “Hello World” in Java
Switch “Hello World” Java to Groovy

Differences from Java
Fewer imports:
java.io
java.math
java.net
java.util
groovy.lang
groovy.util

Differences from Java
The truth
Java:
if (mySet == null || mySet.isEmpty()) {
...
}
Groovy:
if (!mySet) {
...
}

New Operators
?. (NULL-SAFE OBJECT NAVIGATION)
?: (ELVIS!)
*. (THE SPREAD-DOT OPERATOR)
<=> (COMPARISONS WITH A SPACESHIP)
${} (GROOVY STRINGS)
[] (ARRAY-STYLE NOTATION FOR LISTS AND MAPS)

In Java but not in Groovy
Java “FOR” loop
No “DO...WHILE”
Inner and anonymous classes: Not fully
supported

Expert Groovy
Closures: single-method anonymous
classes
[ "apple", "pear", "cherry" ].each { println it }
Duck Typing: Applied to dynamic languages, it means
that if an object has a particular property or method
signature, then it doesn’t matter what type the object
is, you can still call that method or access that
property. This is only possible in dynamic languages
because properties and methods are resolved at
runtime.

Best Practices
Use idiomatic Groovy
Experiment
Use methods where appropriate
Use explicit types in method signatures