Live data from Hacker News

Java 8 Lambdas

datumedge.blogspot.co.uk

21–30 of 144 posts

Re: Java 8 Lambdas

#21
post #9

'sorted()' doesn't really act like that, does it - taking in a comparator function? It's much better to have comparator functions for the most common types baked in, and use projection to select a list of fields to use to compare with. Comparator functions are very easy to get wrong. The example given here - ".sorted((a, b) -> a.getValue() - b.getValue())" - won't work properly when the calculation wraps around.

> It's much better to have comparator functions for the most common types baked in, and use projection to select a list of fields to use to compare with. Except that requires a sorting key for the result. Trivial for dynamically typed languages, but how do you handle the type of that key in a statically typed language? Mandate that the key be a string? Build a limited set of overloads against a dedicated type? And ev…

I don't know what you mean by "sorting key" in this context. The idiom I have in mind is how .Net implements "SortBy", "ThenBy" and friends. Overloads can be used for a comparator function based approach, but it should not be the first choice.

And I'll stand by comparators being easy to get wrong, particularly when values may be null, polymorphic, etc.

Re: Java 8 Lambdas

#22

Would have been a big deal - if they introduced 10 years ago

Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language.

Re: Java 8 Lambdas

#23

Would have been a big deal - if they introduced 10 years ago

Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language.

> Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language.

I hope I am wrong but I smell a trap here. Some time ago I implemented a solution (for .Net, that is) that employed some more modern techniques ( reflection, recursive lambdas, etc). Unfortunately many of the programmers in charge of maintaining my code were either interns from a local technical school or an outsourced company in India. They couldn't get their heads around the techniques I used. They thrashed my code, I ended with a bad reputation and lost the client. Not something I regret, anyway.

Re: Java 8 Lambdas

#24
post #2

Congratulations to the Java-programmers for getting a feature that virtually every other OOP language has had for about 10 years.

The feature has been in Java for a long time. This is just nice syntax for anonymous inner classes.

Re: Java 8 Lambdas

#25

Earlier quoted context omitted.

Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language.

> Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language. I hope I am wrong but I smell a trap here. Some time ago I implemented a solution (for .Net, that is) that employed some more modern techniques ( reflection, recursive lambdas, etc). Unfortunately many of the programmers in charge of maintaining my code w…

Perhaps they didn't approve of your use of reflection? Your post sounds a bit like you would use it because you can create awesome looking code. It should be used rather seldom

http://stackoverflow.com/questions/429962/when-do-you-use-re...

Re: Java 8 Lambdas

#26
post #21

Earlier quoted context omitted.

> It's much better to have comparator functions for the most common types baked in, and use projection to select a list of fields to use to compare with. Except that requires a sorting key for the result. Trivial for dynamically typed languages, but how do you handle the type of that key in a statically typed language? Mandate that the key be a string? Build a limited set of overloads against a dedicated type? And ev…

I don't know what you mean by "sorting key" in this context. The idiom I have in mind is how .Net implements "SortBy", "ThenBy" and friends. Overloads can be used for a comparator function based approach, but it should not be the first choice. And I'll stand by comparators being easy to get wrong, particularly when values may be null, polymorphic, etc.

>I don't know what you mean by "sorting key" in this context.

He means the item by which you sort. The "by" in your "SortBy" example.

Re: Java 8 Lambdas

#27
post #2

Congratulations to the Java-programmers for getting a feature that virtually every other OOP language has had for about 10 years.

Yes, and C doesn't have most things other languages have. That doesn't mean I will use Ruby for my next real time embedded project.

Re: Java 8 Lambdas

#28

Earlier quoted context omitted.

Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language.

> Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language. I hope I am wrong but I smell a trap here. Some time ago I implemented a solution (for .Net, that is) that employed some more modern techniques ( reflection, recursive lambdas, etc). Unfortunately many of the programmers in charge of maintaining my code w…

Sounds familiar

Re: Java 8 Lambdas

#29

Earlier quoted context omitted.

Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language.

> Java is still widely used. I'm looking forward to this -- there are some projects we can't take to Scala due to client concerns around a less mainstream language. I hope I am wrong but I smell a trap here. Some time ago I implemented a solution (for .Net, that is) that employed some more modern techniques ( reflection, recursive lambdas, etc). Unfortunately many of the programmers in charge of maintaining my code w…

I smell trolling, however considering this anecdote is genuine:

(1) interns should never be allowed to commit code in the master branch without a code review from a senior developer

(2) there are many competent developers in India, or around the world, so if your company needs to outsource, it can do so by being a little careful about who they employ

(3) if the above 2 are not possible, simply look for another job, because life is too short

Re: Java 8 Lambdas

#30
post #10

Earlier quoted context omitted.

Python has lambdas and functions as first-order values since the beginning.

You can't have statements in pythons gimped versions of anon functions :/

I call BS.

  def return_closure (value):
      def closure ():
          return value
      return closure

  foo = return_closure(5)
  print foo() # prints 5
If you look closely, foo is an anonymous function, and it could have anything you bloody well please inside of it.

What you can't do is put statements in an anonymous function that you are declaring inline. But the full syntax I just demonstrated is only marginally longer.

UPDATE

Modify the end like this to see that the functions really are anonymous.

  foo = return_closure(1)
  bar = return_closure(2)
  baz = return_closure(3)
  print foo()
  print bar()
  print baz()
You will see that the three functions returned are completely independent. They are not associated with any name or each other. They are, in fact, anonymous. (Admittedly at the moment they are called foo, bar and baz. But you could have put them into an array, and they really would have no unique name.)
Post reply on HN