Groovy brownbag

344 views
317 views

Published on

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

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
344
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 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

    1. 1. WHYGROOVYISSOAWESOME Chris Trevino
    2. 2. “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
    3. 3. About Groovy•Object-oriented•Dynamically Typed•Can use all Java libraries•Feels a lot like Java•Can be compiled or interpreted
    4. 4. Groovy Learning Curve
    5. 5. Most Java is valid Groovy
    6. 6. Steps to Start Using Groovy1) Install eclipse plugin2) Add groovy nature3) Rename .java file .groovy
    7. 7. AWESOMETHINGS
    8. 8. Semicolons are Optional
    9. 9. Semicolons are Optional
    10. 10. ‘public’ is Optional
    11. 11. ‘public’ is Optional
    12. 12. You don’t use package protected anyway
    13. 13. You don’t use package protected anyway (@PackageScope annotation is available if you do)
    14. 14. ‘.class’ is Optional
    15. 15. ‘.class’ is Optional
    16. 16. Getters and Setters are Optional
    17. 17. Getters and Setters are Optional
    18. 18. Getters and Setters are Optional
    19. 19. get..() and set..() are Optional
    20. 20. Lamdba Expressions
    21. 21. AWESOMENESSSO FAR
    22. 22. MOREAWESOMETHINGS
    23. 23. Cleaned up Imports
    24. 24. Cleaned up Imports
    25. 25. Type Declarations are Optional
    26. 26. ‘return’ is Optional
    27. 27. Streamlined Lists
    28. 28. Streamlined Lists
    29. 29. Streamlined Maps
    30. 30. Streamlined Maps
    31. 31. Streamlined Bean Instantiation
    32. 32. Safe Traversal
    33. 33. Elvis
    34. 34. LISTCOMPREHENSIONS
    35. 35. G-Strings
    36. 36. Native Regex Support Match: ==~ Find: =~
    37. 37. Easy File I/O
    38. 38. Easy Markup
    39. 39. Missing Method/Property Handling
    40. 40. Categories / Extension Methods
    41. 41. Extension methods with metaClass
    42. 42. Type Renaming
    43. 43. Hella Dynamic
    44. 44. Hella Dynamic
    45. 45. Hella StaticGroovy++ =>
    46. 46. GROOVYPLAYSNICE

    ×