Groovy brownbag
Upcoming SlideShare
Loading in...5
×
 

Groovy brownbag

on

  • 353 views

Slides for a brown-bag on the Groovy programming language. The talk was given on 11/7/2011.

Slides for a brown-bag on the Groovy programming language. The talk was given on 11/7/2011.

Statistics

Views

Total Views
353
Views on SlideShare
352
Embed Views
1

Actions

Likes
0
Downloads
3
Comments
0

1 Embed 1

http://www.slashdocs.com 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Welcome!I am Chris, and we’re talking about Groovy * Wrote a groovy coral service * Wrote GroovyTrailsMy Goals * Not to cover all aspects of Groovy * Not to convince you to port all of our code * Amuse bouche into the language * Convince you that it’s a good complement to Java
  • The paradox of productivity.
  • * You can incorporate groovy idioms as you ramp up.* You can cherry pick what parts you want
  • Groovy is incredibly easy to learn. * Very java-ish compared to other alternative languages. * My experience was that it took almost no time to learn. * Doesn’t require reading a book or learning a new paradigm.
  • * You can incorporate groovy idioms as you ramp up.* You can cherry pick what parts you want
  • Package protected is rarely used, but an annotation is available.Public and private are most common.
  • Package protected is rarely used, but an annotation is available.Public and private are most common.
  • Package protected is rarely used, but an annotation is available.Public and private are most common.
  • Great for one-off callbacks with frameworks (JdbcTemplates, PreparedStatementCreator, runnables, etc..)
  • So here’s what we started with – pretty vanilla java
  • And we’ve turned it into a trivial amount of code
  • Everything in java.util is imported by default, so you won’t accidentally include emory lists or something.
  • Everything in java.util is imported by default, so you won’t accidentally include emory lists or something.
  • You can use def for defining variables, meaning you don’t have to type class names twice.
  • Excluding return can clean up simple properties and calculations. For larger methods I find that it improves readability to leave them in.
  • Simplified collection construction, very nice!
  • Simplified collection construction, very nice!
  • Simplified collection construction, very nice!
  • Simplified collection construction, very nice!
  • Instead of calling setX, setY, we have a nice way of setting bean properties.Great for simple DI and test construction.
  • Each – you want to do something over every item in a list
  • INJECT!
  • This is what they’re actually called.Removes a lot of ugly code involving string concatenation with plusses, or String.format.
  • Feeds the next example
  • From actual service code.Converting from transport objects to a persisted domain modelPreviously had about 15 lines of anonymous class implementations calling different overloadsOne lambda to rule them all, dynamic multicastWhich is…
  • Defs become implicit.Better compile-time support, loss of dynamicismSpeed parity with Java for performance-sensitive codeAlso addsTraits

Groovy brownbag Groovy brownbag Presentation Transcript

  • WHYGROOVYISSOAWESOME Chris Trevino
  • “Using a computer requires a fair amount ofritual and ceremony…The less you interactwith your computer, the faster you can go.In other words, eliminating ceremony allowsyou to get to the essence of the problem.” Neal Ford – The Productive Programmer
  • About Groovy•Object-oriented•Dynamically Typed•Can use all Java libraries•Feels a lot like Java•Can be compiled or interpreted
  • Groovy Learning Curve
  • Most Java is valid Groovy
  • Steps to Start Using Groovy1) Install eclipse plugin2) Add groovy nature3) Rename .java file .groovy
  • AWESOMETHINGS
  • Semicolons are Optional
  • Semicolons are Optional
  • ‘public’ is Optional
  • ‘public’ is Optional
  • You don’t use package protected anyway
  • You don’t use package protected anyway (@PackageScope annotation is available if you do)
  • ‘.class’ is Optional
  • ‘.class’ is Optional
  • Getters and Setters are Optional
  • Getters and Setters are Optional
  • Getters and Setters are Optional
  • get..() and set..() are Optional
  • Lamdba Expressions
  • AWESOMENESSSO FAR
  • MOREAWESOMETHINGS
  • Cleaned up Imports
  • Cleaned up Imports
  • Type Declarations are Optional
  • ‘return’ is Optional
  • Streamlined Lists
  • Streamlined Lists
  • Streamlined Maps
  • Streamlined Maps
  • Streamlined Bean Instantiation
  • Safe Traversal
  • Elvis
  • LISTCOMPREHENSIONS
  • G-Strings
  • Native Regex Support Match: ==~ Find: =~
  • Easy File I/O
  • Easy Markup
  • Missing Method/Property Handling
  • Categories / Extension Methods
  • Extension methods with metaClass
  • Type Renaming
  • Hella Dynamic
  • Hella Dynamic
  • Hella StaticGroovy++ =>
  • GROOVYPLAYSNICE