• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Functional Programming in Java : Write-only Lambdas?

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Venkat.

As a Java dinosaur (all the way back to V1 of Java) the syntax for Lambdas is pretty impenetrable at times & reminds me of "write-only" code, back in the days of C.
I'm in the middle of reading a book about a different programming language & I have just seen a paragraph taking a swipe at Java lambdas: "It is quite common nowadays to look at code and come away puzzled. Java lambda code is a good example."

Many of your replies in this forum say that functional programming makes code easier to understand. How do you square that with these comments?


Thanks
Don.
 
Author
Posts: 135
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Don,

Programmers can write good code or bad code in any language and in any paradigm. Lambdas are no exception. But, as a team we can do quite a bit to make the code easier to understand and maintainable.

The chapter in the book titled "Functional Programming Idioms" speaks directly to this. Please see the table of contents at https://pragprog.com/titles/vsjava2e/functional-programming-in-java-second-edition

 
Marshal
Posts: 80939
521
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The syntax of the λ expression was introduced new in Java8 and had to be sufficiently different from existing syntax that there would be no confusion with old code. I had to get up to date and learn new syntax when it came in, and now they are usually clear as crystal to me. Usually!
 
Ranch Hand
Posts: 885
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don,
The lambda syntax is different from "normal" Java code, but I don't think it's confusing. If you look at this description from W3Schools I think you'll agree that it's not that hard to understand...

Hoping this helps,
Burk
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lambda Expressions, also known as lambda functions, are anonymous functions that can be passed around and called like regular Java methods. They're a part of Java 8 and onwards, allowing us to write more concise and readable code.

Here's a simple Lambda Expression syntax:  params -> body

Where:

params: are the parameters for the lambda expression.

body: is the code block that Lambda performs.

Refer: https://reloadbasics.com/java/Working_with_Lambda_Expressions for more info
 
Campbell Ritchie
Marshal
Posts: 80939
521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Kumar S wrote:Lambda Expressions, also known as lambda functions . . .

No. a λ function is different from a λ expression. A λ function is a mathematical generalisation of a particular kind of function and a λ expression is a Java® idiom for creating an object. If you look at the old anonymous local class idiom, you will find that you can derive a λ expression from an anonymous class created from a functional interface.

. . . https://reloadbasics.com/ . . .

I hope you didn't write that tutorial, because it is just about the worst tutorial I have ever seen. The code in it is all incorrect.
reply
    Bookmark Topic Watch Topic
  • New Topic