• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

favorite groovy idiom

 
author & internet detective
Posts: 39957
804
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our local user group had a talk on Groovy this evening. One of the things the speaker mentioned was that some new Java programmers write "Java in Groovy" rather than using Groovy idioms.

Does anyone who has used Groovy have an example of something they wish people would do the groovy way?
 
Author
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things jump to mind:

I really like the .each{} language feature. You can iterate over almost everything with .each, and where I can't I end up using metaprogramming to add an .each closure myself... (grin)




The other idiom / language feature I really like is shortening the "getter/setter" call to the field name. You are truly calling the getter/setter behind the scenes, but it cuts down on an _amazing_ amount of visual clutter:

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though my favorite idiom (using each) has already been mentioned by Scott; I also enjoy the following idiom when working with maps.

 
Jeanne Boyarsky
author & internet detective
Posts: 39957
804
Eclipse IDE VI Editor Java
 
See where your hand is? Not there. It's next to this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic