SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
The Buzz About Groovy and Grails




        Presented at

The Chicago Groovy User Group

       by Eric Weimer

      on March 10, 2009
Bio

• Eric B. Weimer
   • 26 years developing software
   • 10 years with Java stack
   • Redpoint Technologies (sponsor)
• Roles
   • Developer
   • Independent consultant
   • Application Architect
   • Project/Program Manager
   • Director Level
• Approach
   • Fun and Agile
   • “Life is a banquet”
Objectives

This talk is a presentation of my research. It will
  answer the following questions:

•   What is Groovy?
•   What is Grails?
•   What do they mean to Java developers?
•   What do they mean to IT managers?
•   Hidden secrets such as “how do I get first class
    plane tickets for the price of coach?”
Groovy Defined

Groovy:
• Is a general purpose programming language
• Is a superset of Java syntax
• Fully Object-Orientated (no primitives!)
• Provides many “next generation” features from
  Smalltalk, Python, Ruby and others.
• Designed to improve productivity
• Has become wildly popular
Grails Defined

Grails:
• Is a web application framework
• Is “full stack”
• Runs on Groovy
• One of many Groovy frameworks available
• Wildly popular
• Leverages Rails‟ Convention over Configuration
• Leverages Closures
Putting it all together


      Groovy

             runs on

 Java Object Model

             runs on

Java Virtual Machine




                                6
Putting it all together


      Groovy

             compiles to

     Bytecode

             runs on

Java Virtual Machine




                                7
Putting it all together


                Frameworks

Grails (web                Griffon (Swing
applications)              applications)




                  Groovy




                                            8
History of computing languages

The first programs looked like this:

0010   1101   0101   1100    0100   1011   0100   1010   1011   1100
0110   1110   0001   0000    0101   0011   0010   1111   0111   0011
0101   0011   0100   1111    0001   1000   0110   0101   1011   1100
0010   1101   0101   1100    0100   1011   0100   1010   0111   0011
0110   1110   0001   0000    0101   0011   0010   1111   1011   1100
0101   0011   0100   1111    0001   1000   0110   0101   0111   0011
0010   1101   0101   1100    0100   1011   0100   1010   1011   1100
0110   1110   0001   0000    0101   0011   0010   1111   0111   0011
0101   0011   0100   1111    0001   1000   0110   0101   1011   1100
0010   1101   0101   1100    0100   1011   0100   1010   0111   0011
0110   1110   0001   0000    0101   0011   0010   1111   1011   1100
0101   0011   0100   1111    0001   1000   0110   0101   0111   0011
Historical Documents
Early Russian Programmers
Programming was quite lucrative
How do I install Groovy and Grails


Easy:
• Download and unzip Groovy and Grails
• Set GROOVY_HOME, GRAILS_HOME
• Add %GROOVY_HOME%/bin to Path
• Add %GRAILS_HOME%/bin to Path
Optional:
• Install your IDE‟s Groovy plugin
Groovy Buzz Words

•   Groovy Truth
•   Duck Typing
•   Syntactic Sugar
•   Fully Object Orientated
•   Closures
•   Dynamic Objects
•   Mixins
•   Meta Object Protocol
•   And more…
Groovy Truth

How Groovy handles boolean comparisons
•Groovy supports the standard conditional operators on
boolean expressions
•In addition, Groovy has special rules for coercing non-
boolean objects to a boolean value.
•Empty collections are false, non-empty are true.
•Empty maps are false, non-empty are true.
•Null object references are false, non-null are true.
•Non-zero numbers are true.
Groovy Truth

Examples:

def obj = null;
if ( obj ) …

obj = new Person()
if ( obj ) …

def numSnakes = 0
if ( numSnakes ) …
Duck Typing

If it looks like a duck and quacks like a duck, …

def identity = new Identity()
…
identity = new Person()
…
identity = “Eric”
Syntactic Sugar

Syntactic Sugar
•An alternative syntax
•More concise
•Improved clarity
•Improves productivity
•Syntactic sugar usually provides no additional
functionality
Syntactic Sugar
// Semicolons are only required when necessary:
String friend = „Matt‟

// Parentheses are optional
println “eric has ${numDogs}‟s dogs”

// Except when the compiler cannot tell:
person.save(); children.save()

// return is optional
Syntactic Sugar
// Class variables are private by default in Groovy.
// Groovy generates the getters and setters for you:

class Person {
       String firstName
       String lastName
}
// In Groovy these are the same:

String firstName = p.getLastName( )
String firstName = p.lastName
Syntactic Sugar

// Groovy makes great use of the dot operator.
//
// Consider a web page. Groovy supports syntax for navigating
// hierarchical structures with Groovy Builders:

def page = DomBuilder( … )

// Get all the anchors in a page
List anchors = page.html.body.‟**‟.a
Syntactic Sugar

// Groovy supports the Java for loop:

for (int i = 0; i < 10; i++) { … }

// However a “sweeter” version of this is

(0..9).each { … }

// Or just

10.times { … }
Syntactic Sugar


// constructor sweetness
def person = new Person(
   firstName: quot;Ericquot;,
   lastName: quot;Weimerquot;,
   address: new Address(
        addressLine1: quot;101 Main Streetquot;,
        city: quot;Lislequot;,
        zipCode: quot;60532quot;)
)
Syntactic Sugar

//Define an ArrayList:
def petList = [„Rocket‟,‟Portia‟,‟Cleo‟,‟Java‟]

// Define a HashMap
def employeeCellPhoneMap =
      [Karl: „847-699-3222‟,
       Emelye: „630-605-4355‟,
       Natalie: „312-555-1234‟]
Fully Object Orientated

// Common Java bug

public boolean sameName (String aName) {
  String name = “Matt”;
  return name == aName;
}
…
boolean b = sameName(“Matt”);
Fully Object Orientated

Java primitives (int, short, long, double, char, etc.)

•   In Java, operators only make sense for primitives
•   What to do with comparison operators? (==, >, <, ...)
•   Answer: Make them work for objects
•   Via operator overloading!
•   But isn‟t operator overloading a bad thing?
•   Not unless it is abused…
•   Groovy makes it intuitive
Groovy Operators

Groovy Comparison Operators
Operator  Method
a == b    a.equals(b)
a>b       a.compareTo(b) > 0
a >= b    a.compareTo(b) >= 0
a<b       a.compareTo(b) < 0
a <= b    a.compareTo(b) <= 0
Groovy Math-like operators
Groovy Math-like operators
Operator         Method
a+b              a.plus(b)
a-b              a.minus(b)
a*b              a.multiply(b)
a/b              a.divide(b)
a++ or ++a       a.next()
a-- or --a       a.previous()
a << b           a.leftShift(b)

Array Operators
Operator          Method
a[b]              a.getAt(b)
a[b] = c          a.putAt(b, c)
Fully Object Orientated



// Groovy version works as expected!
public Boolean sameName (String aName)
  {
String name = “Stu”
name == aName
}
…
boolean b = sameName(“Stu”);
Closures


• A closure in Groovy is an object
•   Java has syntax for strings: String x=“eric”;
•   Groovy contains a syntax for closures
•   In Groovy, a closure is defined by braces {…}
•   As an object, you may assign it to a variable
•   As an object, you may pass it to methods
•   It can also reference any variables in scope
Closures



// A trivial example:
public void printList(List a) {
   def pl = {println it}
   a.each (pl)
}
Closures in Grails


class   ItemController {
  def   save = { …
  }
  def   search = { …
  }
  def   get = {
  }
}
Dynamic Objects

• You can add methods and properties to classes
  or objects.
• You can intercept method calls.
• Many examples such as tracking changes to a
  POGO or POJO, logging, business rules, etc.
Mixins


Add methods to ANY class at runtime (even Java final).

// Assume you‟ve defined methods wordCount,
charCount:

File.mixin WordCount, CharCount
Meta Object Protocol

Metaprogramming

Metaclasses represent the runtime behavior of your
classes and instances. Available per class and per
instance.

ExpandoMetaClass DSL streamlines metaclass use.

Number.metaClass.multiply = { Amount amount ->
amount.times(delegate) }
Meta Object Protocol

Metaprogramming

Metaclasses can add properties:

File.metaClass.getWordCount = {
      delegate.text.split(/w/).size()
}

new File('myFile.txt').wordCount
There is much more to Groovy


•   Builders
•   DSL
•   Swing support (Griffon)
•   Template framework
•   Groovy Server Pages
•   AST transformations
•   Grape
•   JMX Builder, OSGi support, etc. etc. etc.
Grails – what is it?


• Grails is a modern, full stack web application
  framework in a box
• Grails is built in Spring and Hibernate
• Grails comes complete with a web server,
  database, testing framework, automated build and
  logging.
• Grails is not an RoR clone, it is inspired by Rails.
• Best demoed by example.
Grails – what is it?


• A full stack web framework built on Groovy
• Leverages proven industry standards like Spring
  and Hibernate
• Supports “Convention over configuration” like Rails
• Makes use of closures like Rails
• Not designed to be a Groovy-based Rails, but
  designed to be better than Rails
Groovy Myths

•   Groovy is a scripting language
•   Sun favors JRuby over Groovy
•   Groovy is slow and full of bugs
•   Java is sufficient for our needs
•   Now that SpringSource has acquired Groovy,
    and now that Spring favors paying customers,
    does that mean Groovy is destined to be closed
    source and require a fee?
Barriers to entry

Approval to use a new language can be difficult.
• Some shops require an elaborate process to
  approve a new language.
• Hint: Begin with Groovy for unit testing
• Hint: Use Groovy for Ant scripting
• Present results of polls, statistics, etc. to show
  Groovy has a large community of support
• Create a compelling argument for Groovy
  adoption
• Emphasize productivity gains, competitive
  advantage
In conclusion
How compelling are Groovy and Grails?
• Production ready
• Improves developer productivity
• Reduces bugs
• Eases migration for legacy Java developers
• Excellent documentation
• Community is growing geometrically
• Mainstream community awareness through
  SpringSource
• Widespread anecdotal evidence of the claims above
• Lacks published metrics to support claims above
Recommended Reading

For beginners without Rails or Django experience:

Beginning Groovy and Grails: From Novice to Professional (Beginning from Novice to
   Professional) by Christopher M. Judd, Joseph Faisal Nusairat, and Jim Shingler
Groovy and Grails Recipes (Recipes: a Problem-Solution Approach) by Bashar Abdul-Jawad

For the experienced:

Groovy in Action by Dierk Koenig, Andrew Glover, Paul King, and Guillaume Laforge
Programming Groovy: Dynamic Productivity for the Java Developer (Pragmatic
   Programmers) by Venkat Subramaniam
Groovy Recipes: Greasing the Wheels of Java (Pragmatic Programmers) by Scott Davis
The Definitive Guide to Grails, Second Edition (Expert's Voice in Web Development) by
   Graeme Rocher and Jeff Brown
In conclusion



       You can find these slides on my blog at:
            ericbweimer.blogspot.com

                   Thanks for coming!
Don‟t forget to stay for the prizes donated by Redpoint.

Weitere ähnliche Inhalte

Was ist angesagt?

Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceJesse Vincent
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovypaulbowler
 
Groovy Grails DevJam Jam Session
Groovy Grails DevJam Jam SessionGroovy Grails DevJam Jam Session
Groovy Grails DevJam Jam SessionMike Hugo
 
Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015Jorge Franco Leza
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyIván López Martín
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsTobias Oetiker
 
Using Grails to power your electric car
Using Grails to power your electric carUsing Grails to power your electric car
Using Grails to power your electric carMarco Pas
 
C++ interoperability with other languages
C++ interoperability with other languagesC++ interoperability with other languages
C++ interoperability with other languagesAlberto Bignotti
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To GrailsEric Berry
 
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020Johnny Sung
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedFabian Jakobs
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?PVS-Studio
 
Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.Alberto Naranjo
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Guillaume Laforge
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsMarcin Grzejszczak
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyIván López Martín
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentSchalk Cronjé
 

Was ist angesagt? (20)

Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret Sauce
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovy
 
Groovy Grails DevJam Jam Session
Groovy Grails DevJam Jam SessionGroovy Grails DevJam Jam Session
Groovy Grails DevJam Jam Session
 
Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015Grooscript in Action SpringOne2gx 2015
Grooscript in Action SpringOne2gx 2015
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
Using Grails to power your electric car
Using Grails to power your electric carUsing Grails to power your electric car
Using Grails to power your electric car
 
C++ interoperability with other languages
C++ interoperability with other languagesC++ interoperability with other languages
C++ interoperability with other languages
 
how u can learn C/C++
how u can learn C/C++ how u can learn C/C++
how u can learn C/C++
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To Grails
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?
 
Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovy
 
Using the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM DevelopmentUsing the Groovy Ecosystem for Rapid JVM Development
Using the Groovy Ecosystem for Rapid JVM Development
 

Andere mochten auch

Product Datasheet Nu Surveillance 360
Product Datasheet Nu Surveillance 360Product Datasheet Nu Surveillance 360
Product Datasheet Nu Surveillance 360ch1ris
 
7. professional teaching standards
7. professional teaching standards7. professional teaching standards
7. professional teaching standardsNgan Jiaing
 
DATIA Conference 2010 - Social Media
DATIA Conference 2010 - Social MediaDATIA Conference 2010 - Social Media
DATIA Conference 2010 - Social Mediaterrimcculloch
 
6. pendekatan pengajaran
6. pendekatan pengajaran6. pendekatan pengajaran
6. pendekatan pengajaranNgan Jiaing
 
Updated Nu Surveillance Power Point
Updated Nu Surveillance Power PointUpdated Nu Surveillance Power Point
Updated Nu Surveillance Power Pointch1ris
 
11. school culture
11. school culture11. school culture
11. school cultureNgan Jiaing
 

Andere mochten auch (9)

Product Datasheet Nu Surveillance 360
Product Datasheet Nu Surveillance 360Product Datasheet Nu Surveillance 360
Product Datasheet Nu Surveillance 360
 
4. akses ekuiti
4. akses ekuiti4. akses ekuiti
4. akses ekuiti
 
7. professional teaching standards
7. professional teaching standards7. professional teaching standards
7. professional teaching standards
 
DATIA Conference 2010 - Social Media
DATIA Conference 2010 - Social MediaDATIA Conference 2010 - Social Media
DATIA Conference 2010 - Social Media
 
6. pendekatan pengajaran
6. pendekatan pengajaran6. pendekatan pengajaran
6. pendekatan pengajaran
 
Presentation
PresentationPresentation
Presentation
 
Updated Nu Surveillance Power Point
Updated Nu Surveillance Power PointUpdated Nu Surveillance Power Point
Updated Nu Surveillance Power Point
 
11. school culture
11. school culture11. school culture
11. school culture
 
3. timss
3. timss3. timss
3. timss
 

Ähnlich wie Groovy And Grails Introduction

Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGuillaume Laforge
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for JavaCharles Anderson
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
Practical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyPractical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyGuillaume Laforge
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf
 
Groovy Online 100
Groovy Online 100Groovy Online 100
Groovy Online 100reynolds
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingAndres Almiray
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyJames Williams
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyAndres Almiray
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleySven Haiges
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applicationsrohitnayak
 
Dsl로 만나는 groovy
Dsl로 만나는 groovyDsl로 만나는 groovy
Dsl로 만나는 groovySeeyoung Chang
 
greach 2014 marco vermeulen bdd using cucumber jvm and groovy
greach 2014 marco vermeulen bdd using cucumber jvm and groovygreach 2014 marco vermeulen bdd using cucumber jvm and groovy
greach 2014 marco vermeulen bdd using cucumber jvm and groovyJessie Evangelista
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Tugdual Grall
 

Ähnlich wie Groovy And Grails Introduction (20)

Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for Java
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
Whats New In Groovy 1.6?
Whats New In Groovy 1.6?Whats New In Groovy 1.6?
Whats New In Groovy 1.6?
 
Practical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyPractical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in Groovy
 
Groovy intro
Groovy introGroovy intro
Groovy intro
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 
Groovy Online 100
Groovy Online 100Groovy Online 100
Groovy Online 100
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon Valley
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Dsl로 만나는 groovy
Dsl로 만나는 groovyDsl로 만나는 groovy
Dsl로 만나는 groovy
 
greach 2014 marco vermeulen bdd using cucumber jvm and groovy
greach 2014 marco vermeulen bdd using cucumber jvm and groovygreach 2014 marco vermeulen bdd using cucumber jvm and groovy
greach 2014 marco vermeulen bdd using cucumber jvm and groovy
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007
 

Kürzlich hochgeladen

Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 

Kürzlich hochgeladen (20)

Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 

Groovy And Grails Introduction

  • 1. The Buzz About Groovy and Grails Presented at The Chicago Groovy User Group by Eric Weimer on March 10, 2009
  • 2. Bio • Eric B. Weimer • 26 years developing software • 10 years with Java stack • Redpoint Technologies (sponsor) • Roles • Developer • Independent consultant • Application Architect • Project/Program Manager • Director Level • Approach • Fun and Agile • “Life is a banquet”
  • 3. Objectives This talk is a presentation of my research. It will answer the following questions: • What is Groovy? • What is Grails? • What do they mean to Java developers? • What do they mean to IT managers? • Hidden secrets such as “how do I get first class plane tickets for the price of coach?”
  • 4. Groovy Defined Groovy: • Is a general purpose programming language • Is a superset of Java syntax • Fully Object-Orientated (no primitives!) • Provides many “next generation” features from Smalltalk, Python, Ruby and others. • Designed to improve productivity • Has become wildly popular
  • 5. Grails Defined Grails: • Is a web application framework • Is “full stack” • Runs on Groovy • One of many Groovy frameworks available • Wildly popular • Leverages Rails‟ Convention over Configuration • Leverages Closures
  • 6. Putting it all together Groovy runs on Java Object Model runs on Java Virtual Machine 6
  • 7. Putting it all together Groovy compiles to Bytecode runs on Java Virtual Machine 7
  • 8. Putting it all together Frameworks Grails (web Griffon (Swing applications) applications) Groovy 8
  • 9. History of computing languages The first programs looked like this: 0010 1101 0101 1100 0100 1011 0100 1010 1011 1100 0110 1110 0001 0000 0101 0011 0010 1111 0111 0011 0101 0011 0100 1111 0001 1000 0110 0101 1011 1100 0010 1101 0101 1100 0100 1011 0100 1010 0111 0011 0110 1110 0001 0000 0101 0011 0010 1111 1011 1100 0101 0011 0100 1111 0001 1000 0110 0101 0111 0011 0010 1101 0101 1100 0100 1011 0100 1010 1011 1100 0110 1110 0001 0000 0101 0011 0010 1111 0111 0011 0101 0011 0100 1111 0001 1000 0110 0101 1011 1100 0010 1101 0101 1100 0100 1011 0100 1010 0111 0011 0110 1110 0001 0000 0101 0011 0010 1111 1011 1100 0101 0011 0100 1111 0001 1000 0110 0101 0111 0011
  • 13. How do I install Groovy and Grails Easy: • Download and unzip Groovy and Grails • Set GROOVY_HOME, GRAILS_HOME • Add %GROOVY_HOME%/bin to Path • Add %GRAILS_HOME%/bin to Path Optional: • Install your IDE‟s Groovy plugin
  • 14. Groovy Buzz Words • Groovy Truth • Duck Typing • Syntactic Sugar • Fully Object Orientated • Closures • Dynamic Objects • Mixins • Meta Object Protocol • And more…
  • 15. Groovy Truth How Groovy handles boolean comparisons •Groovy supports the standard conditional operators on boolean expressions •In addition, Groovy has special rules for coercing non- boolean objects to a boolean value. •Empty collections are false, non-empty are true. •Empty maps are false, non-empty are true. •Null object references are false, non-null are true. •Non-zero numbers are true.
  • 16. Groovy Truth Examples: def obj = null; if ( obj ) … obj = new Person() if ( obj ) … def numSnakes = 0 if ( numSnakes ) …
  • 17. Duck Typing If it looks like a duck and quacks like a duck, … def identity = new Identity() … identity = new Person() … identity = “Eric”
  • 18. Syntactic Sugar Syntactic Sugar •An alternative syntax •More concise •Improved clarity •Improves productivity •Syntactic sugar usually provides no additional functionality
  • 19. Syntactic Sugar // Semicolons are only required when necessary: String friend = „Matt‟ // Parentheses are optional println “eric has ${numDogs}‟s dogs” // Except when the compiler cannot tell: person.save(); children.save() // return is optional
  • 20. Syntactic Sugar // Class variables are private by default in Groovy. // Groovy generates the getters and setters for you: class Person { String firstName String lastName } // In Groovy these are the same: String firstName = p.getLastName( ) String firstName = p.lastName
  • 21. Syntactic Sugar // Groovy makes great use of the dot operator. // // Consider a web page. Groovy supports syntax for navigating // hierarchical structures with Groovy Builders: def page = DomBuilder( … ) // Get all the anchors in a page List anchors = page.html.body.‟**‟.a
  • 22. Syntactic Sugar // Groovy supports the Java for loop: for (int i = 0; i < 10; i++) { … } // However a “sweeter” version of this is (0..9).each { … } // Or just 10.times { … }
  • 23. Syntactic Sugar // constructor sweetness def person = new Person( firstName: quot;Ericquot;, lastName: quot;Weimerquot;, address: new Address( addressLine1: quot;101 Main Streetquot;, city: quot;Lislequot;, zipCode: quot;60532quot;) )
  • 24. Syntactic Sugar //Define an ArrayList: def petList = [„Rocket‟,‟Portia‟,‟Cleo‟,‟Java‟] // Define a HashMap def employeeCellPhoneMap = [Karl: „847-699-3222‟, Emelye: „630-605-4355‟, Natalie: „312-555-1234‟]
  • 25. Fully Object Orientated // Common Java bug public boolean sameName (String aName) { String name = “Matt”; return name == aName; } … boolean b = sameName(“Matt”);
  • 26. Fully Object Orientated Java primitives (int, short, long, double, char, etc.) • In Java, operators only make sense for primitives • What to do with comparison operators? (==, >, <, ...) • Answer: Make them work for objects • Via operator overloading! • But isn‟t operator overloading a bad thing? • Not unless it is abused… • Groovy makes it intuitive
  • 27. Groovy Operators Groovy Comparison Operators Operator Method a == b a.equals(b) a>b a.compareTo(b) > 0 a >= b a.compareTo(b) >= 0 a<b a.compareTo(b) < 0 a <= b a.compareTo(b) <= 0
  • 28. Groovy Math-like operators Groovy Math-like operators Operator Method a+b a.plus(b) a-b a.minus(b) a*b a.multiply(b) a/b a.divide(b) a++ or ++a a.next() a-- or --a a.previous() a << b a.leftShift(b) Array Operators Operator Method a[b] a.getAt(b) a[b] = c a.putAt(b, c)
  • 29. Fully Object Orientated // Groovy version works as expected! public Boolean sameName (String aName) { String name = “Stu” name == aName } … boolean b = sameName(“Stu”);
  • 30. Closures • A closure in Groovy is an object • Java has syntax for strings: String x=“eric”; • Groovy contains a syntax for closures • In Groovy, a closure is defined by braces {…} • As an object, you may assign it to a variable • As an object, you may pass it to methods • It can also reference any variables in scope
  • 31. Closures // A trivial example: public void printList(List a) { def pl = {println it} a.each (pl) }
  • 32. Closures in Grails class ItemController { def save = { … } def search = { … } def get = { } }
  • 33. Dynamic Objects • You can add methods and properties to classes or objects. • You can intercept method calls. • Many examples such as tracking changes to a POGO or POJO, logging, business rules, etc.
  • 34. Mixins Add methods to ANY class at runtime (even Java final). // Assume you‟ve defined methods wordCount, charCount: File.mixin WordCount, CharCount
  • 35. Meta Object Protocol Metaprogramming Metaclasses represent the runtime behavior of your classes and instances. Available per class and per instance. ExpandoMetaClass DSL streamlines metaclass use. Number.metaClass.multiply = { Amount amount -> amount.times(delegate) }
  • 36. Meta Object Protocol Metaprogramming Metaclasses can add properties: File.metaClass.getWordCount = { delegate.text.split(/w/).size() } new File('myFile.txt').wordCount
  • 37. There is much more to Groovy • Builders • DSL • Swing support (Griffon) • Template framework • Groovy Server Pages • AST transformations • Grape • JMX Builder, OSGi support, etc. etc. etc.
  • 38. Grails – what is it? • Grails is a modern, full stack web application framework in a box • Grails is built in Spring and Hibernate • Grails comes complete with a web server, database, testing framework, automated build and logging. • Grails is not an RoR clone, it is inspired by Rails. • Best demoed by example.
  • 39. Grails – what is it? • A full stack web framework built on Groovy • Leverages proven industry standards like Spring and Hibernate • Supports “Convention over configuration” like Rails • Makes use of closures like Rails • Not designed to be a Groovy-based Rails, but designed to be better than Rails
  • 40. Groovy Myths • Groovy is a scripting language • Sun favors JRuby over Groovy • Groovy is slow and full of bugs • Java is sufficient for our needs • Now that SpringSource has acquired Groovy, and now that Spring favors paying customers, does that mean Groovy is destined to be closed source and require a fee?
  • 41. Barriers to entry Approval to use a new language can be difficult. • Some shops require an elaborate process to approve a new language. • Hint: Begin with Groovy for unit testing • Hint: Use Groovy for Ant scripting • Present results of polls, statistics, etc. to show Groovy has a large community of support • Create a compelling argument for Groovy adoption • Emphasize productivity gains, competitive advantage
  • 42. In conclusion How compelling are Groovy and Grails? • Production ready • Improves developer productivity • Reduces bugs • Eases migration for legacy Java developers • Excellent documentation • Community is growing geometrically • Mainstream community awareness through SpringSource • Widespread anecdotal evidence of the claims above • Lacks published metrics to support claims above
  • 43. Recommended Reading For beginners without Rails or Django experience: Beginning Groovy and Grails: From Novice to Professional (Beginning from Novice to Professional) by Christopher M. Judd, Joseph Faisal Nusairat, and Jim Shingler Groovy and Grails Recipes (Recipes: a Problem-Solution Approach) by Bashar Abdul-Jawad For the experienced: Groovy in Action by Dierk Koenig, Andrew Glover, Paul King, and Guillaume Laforge Programming Groovy: Dynamic Productivity for the Java Developer (Pragmatic Programmers) by Venkat Subramaniam Groovy Recipes: Greasing the Wheels of Java (Pragmatic Programmers) by Scott Davis The Definitive Guide to Grails, Second Edition (Expert's Voice in Web Development) by Graeme Rocher and Jeff Brown
  • 44. In conclusion You can find these slides on my blog at: ericbweimer.blogspot.com Thanks for coming! Don‟t forget to stay for the prizes donated by Redpoint.