• 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

How many of you use lambda expressions?

 
Ranch Hand
Posts: 574
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've read about them in other languages but never seen a need for them.  I suspect they're like associative arrays.  For years I couldn't image how they would be useful, as an engineer all I dealt with was numbers.  Then I had to, um, "text crunch" log files and the light bulb lit.
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no need for them. Everything you can do with a lambda you can do with an (anonymous) class that implements the functional interface. I'm sure you've used those on occasion. Lambdas are just much more succinct. They remove a lot of boilerplate from your code. I've almost completely eliminated my use of anonymous classes since the introduction of Java 8.

However, I use them a lot less than at the start: I much more prefer to use method references, because they make the code even more declarative. With method references, you truly write down the What, and not the How.
 
gunslinger & author
Posts: 169
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lambdas (and method references) come up when you're writing Stream pipeline code. One of the advantages to writing that way is that, in addition to generally being simpler and easier to follow, you can also change the stream to a parallel one and experiment with concurrency.

Also, when you start using lambdas, many design patterns completely vanish. Most of the so-called "behavior" patterns in the original Gang of Four book are simply ways to wrap lambdas inside objects. See the articles by Mario Fusco for some good examples.
 
Jim Venolia
Ranch Hand
Posts: 574
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kenneth A. Kousen wrote:Lambdas (and method references) come up when you're writing Stream pipeline code..



Ah.  I tend to write device driver code, Linux kernel internals, and lately have been parsing text log files.  Only the log file parsing has been in Java, everything else is C.

Actually, it sounds a lot like state machine code I've written, where everything is a pointer to a function (written in C).  Done that twice, both were, um, interesting.

As I said in my original post, I suspect when I need it I'll know it, but until then it will be a "who the hell needs this" kinds thing.

CSB time
Found myself troubleshooting some battery charging code.  It was implemented as a state machine.  The problem turned out to be hardware.

Several months later I got loaned to another group (I was a generic troubleshooter at the time), mentioned to the woman I was working with that that battery code was some of the sweetest code I'd ever run across.  She offered to introduce me to the guy that wrote it.  I was, I dunno, 45-50 at the time.  He was a 20 something H1-B.  I was embarrassed at the way he took my compliment, I had never before, nor ever again, been treated as a programming god.
/ CSB
 
You may have just won ten million dollars! Or, maybe a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic