• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

does groovy have anything like System.out::println

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really like being about to write code like this in Java:



Is there anything concise like that in Groovy for printing out? (I'm writing utility scripts so I do a lot of printing out values).
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this the kind of thing you want?
Running this in the Groovy console produces the following output:
You can use the "each" method on pretty much any collection, and provide it with pretty much any code that you want to execute for each element in the collection. Pretty concise and nicely generic.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer to my question is no. It's not a big deal. I just like that Java lets you say "print the current value" rather than having to write the println out like you showed.
 
chris webster
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dunno:seems pretty tidy to me. Can't help feeling that new improved functional Java is still doing the Java-thing of making everything a bit more awkward than necessary. A matter of taste, I guess!
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been trying to avoid "it" because I don't think my co-workers will know what it means.
 
chris webster
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:I've been trying to avoid "it" because I don't think my co-workers will know what it means.


Aren't they IT workers?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:I've been trying to avoid "it" because I don't think my co-workers will know what it means.



I really hope that if they are working in Groovy, they know what "it" means, because it is very important basic to know with Groovy and Closures.

Also I recommend using. ${} in your Strings instead of concatenation. But not in log messages. In Slf4J logging for instance it is best to do log.debug("My message with a {} placeholder", valueOfPlaceholder)

As it does some tuning where unless the level is debug it doesn't do the String evaluation.

Mark
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:I really hope that if they are working in Groovy, they know what "it" means, because it is very important basic to know with Groovy and Closures.


We aren't using a ton of Groovy. I (by far) know the most Groovy of anyone on the team. (These are scripts and not long programs.) And I've been using explicit names up until now, so "it" hasn't shown up.

Mark Spritzler wrote:Also I recommend using. ${} in your Strings instead of concatenation. But not in log messages. In Slf4J logging for instance it is best to do log.debug("My message with a {} placeholder", valueOfPlaceholder)


I ise ${} "sometimes". (aka "when I remember"). Performance doesn't matter for what we are running though. So I'm doing it more to develop good habits and make the code easier to read.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic