exo ec - groovy programming language
TRANSCRIPT
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 truthJava:
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 doesnt 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
Click to edit the title text format