Lambdas: New to Java 8, New to Flukeshot

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 5570 Views - Last Post: 07 June 2014 - 10:12 PM

#1 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 415
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Lambdas: New to Java 8, New to Flukeshot

Post icon  Posted 20 January 2014 - 09:38 PM

*
POPULAR

So, as you guys already know, Java is the first OOP language I've put serious time into, and with the upcoming release of Java 8 I've been seeing the term 'Lambda' thrown around quite often.

My question is not really about what lambdas are, I understand they are (in layman's terms) anonymous methods created inside other methods. Rather, my question is what purpose does this ability serve?

I'm sure this question is bound to create a decent discussion of past applications of the mechanic, so I'm looking forward to your answers!

Is This A Good Question/Topic? 5
  • +

Replies To: Lambdas: New to Java 8, New to Flukeshot

#2 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1948
  • View blog
  • Posts: 4,048
  • Joined: 11-December 07

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 10:50 AM

Amongst other things, it will make your event listeners sexy.
Was This Post Helpful? 1
  • +
  • -

#3 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 11:48 AM

This immediately reminded me of the "A Brief, Incomplete, and Mostly Wrong History of Programming Languages"

Quote

1970 - Guy Steele and Gerald Sussman create Scheme. Their work leads to a series of "Lambda the Ultimate" papers culminating in "Lambda the Ultimate Kitchen Utensil." This paper becomes the basis for a long running, but ultimately unsuccessful run of late night infomercials. Lambdas are relegated to relative obscurity until Java makes them popular by not having them.


Looks like that is all changing :sorcerer:
Was This Post Helpful? 0
  • +
  • -

#4 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 12:03 PM

No more annoying and verbose anonymous classes flying about everywhere. (pretty much the same as what cfoley said).

LINQ clones! If you're familiar with .Net, this should excite you.
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7621
  • View blog
  • Posts: 12,849
  • Joined: 19-March 11

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 12:36 PM

I'm not sure what all the fuss is about. If you want to do functional programming on the jvm, scala seems like the preferred option.
Was This Post Helpful? 0
  • +
  • -

#6 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5795
  • View blog
  • Posts: 12,628
  • Joined: 16-October 07

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 12:47 PM

One of my criticisms of Scala is that it's a bit of a kitchen sink. C# has become a kitchen sink over time, but Scala surpassed that as an initial design choice.

One of the nice things about Java was it's almost fundamentalist vision of OOP via classes. You could count on Java to take the moral OO high road. Let other JVM languages do that other stuff.

Until now.

I'd have to play with it. I use lambdas in C# a lot now. They'll probably creep into my Java. Unless, of course, they suck.
Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7621
  • View blog
  • Posts: 12,849
  • Joined: 19-March 11

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 12:58 PM

Quote

One of my criticisms of Scala is that it's a bit of a kitchen sink.


That's true - but any language that's useful is going to get that way over time. I don't mind a kitchen sink, actually. It makes it a lot easier to wash dishes.

Quote

One of the nice things about Java was it's almost fundamentalist vision of OOP via classes. You could count on Java to take the moral OO high road.


I'm never sure how to make this distinction between OO and functional make sense. To me it seems like the difference between cooking "a stew" and "with garlic". Is there any way in which the two are incompatible?
Was This Post Helpful? 0
  • +
  • -

#8 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1948
  • View blog
  • Posts: 4,048
  • Joined: 11-December 07

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 03:20 PM

There is no distinction between OO and functional. There is one between imperative and functional. Imperative is when you give the computer commands to perform. Functional is when you give it functions to evaluate. I'm sure there are tighter definitions out there. However, my point is that either can be object orientated. Lisp is an example of a functional language that can be object orientated.

Most functional languages do have imperative aspects. They have special mutable variables and special commands to manipulate them. What's wrong with including traditionally functional features in imperative languages?
Was This Post Helpful? 1
  • +
  • -

#9 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7621
  • View blog
  • Posts: 12,849
  • Joined: 19-March 11

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 03:44 PM

Gee, Chris, it feels almost like we've talked about this before. :)
Was This Post Helpful? 0
  • +
  • -

#10 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1948
  • View blog
  • Posts: 4,048
  • Joined: 11-December 07

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 03:48 PM

Flukeshot, there is a Coursera course (Programming Languages by Dan Grossman) that I found valuable. It uses three languages to take you on a journey starting with functional programming and going through to object orientation with a mix of imperative and functional styles.

When I did the course, it perfectly filled a hole in my knowledge. It was the right time for me to do that course. If you are saying that you know what lambdas are but don't know why you would want to use them then maybe you are in the same position I was.
Was This Post Helpful? 1
  • +
  • -

#11 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5795
  • View blog
  • Posts: 12,628
  • Joined: 16-October 07

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 04:50 PM

View Postjon.kiparsky, on 21 January 2014 - 02:58 PM, said:

That's true - but any language that's useful is going to get that way over time.


Agreed. It's just, Scala started that way.

View Postjon.kiparsky, on 21 January 2014 - 02:58 PM, said:

I'm never sure how to make this distinction between OO and functional make sense.


I didn't do that. Rather, I noted that Java has often pushed back against language features, contending that it's purity of structure is both sufficient and desirable. This has changed over time.

Events were noted. C#'s event system started quite elegant with the use of delegates. Java refused to implement similar features... until now.
Was This Post Helpful? 0
  • +
  • -

#12 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 415
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 21 January 2014 - 05:46 PM

View Postcfoley, on 21 January 2014 - 10:48 PM, said:

Flukeshot, there is a Coursera course (Programming Languages by Dan Grossman) that I found valuable. It uses three languages to take you on a journey starting with functional programming and going through to object orientation with a mix of imperative and functional styles.

Thanks Chris! I'm going to set aside time to work through this course

View Postcfoley, on 21 January 2014 - 10:48 PM, said:

When I did the course, it perfectly filled a hole in my knowledge. It was the right time for me to do that course. If you are saying that you know what lambdas are but don't know why you would want to use them then maybe you are in the same position I was.

It sounds about right, I was looking for some real-life examples of uses of lamda functions but my search came up short. Does the course cover anything like that?
Was This Post Helpful? 0
  • +
  • -

#13 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1948
  • View blog
  • Posts: 4,048
  • Joined: 11-December 07

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 22 January 2014 - 03:38 AM

Like all courses, the exercises are often contrived but they certainly do ask you to use lambdas to solve problems. Sometimes using a lambda seems to make things easier or clearer and sometimes it makes it more obscure. It's not just lambdas either. Currying and pattern matching are other concepts I enjoyed learning about.
Was This Post Helpful? 0
  • +
  • -

#14 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,531
  • Joined: 29-July 11

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 01 February 2014 - 07:05 AM

The best resource I have seen on Lambdas in java

It is also interesting to note that like in c#, they are just syntactic sugar, as far as I understand. When you write one, the compiler just generates the anonymous class in the bytecode anyway.

This post has been edited by farrell2k: 01 February 2014 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

#15 Ravioli27  Icon User is offline

  • New D.I.C Head

Reputation: 10
  • View blog
  • Posts: 34
  • Joined: 03-December 12

Re: Lambdas: New to Java 8, New to Flukeshot

Posted 27 March 2014 - 11:43 PM

I am currently learning about lambda expressions in python. so this works out for me :D.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2