3 ms·
why does a language designed around an OOP perspective need a lambda (which comes from a functional programming perspective)?
by joshAg 14y ago
why does a language designed around an OOP perspective need a lambda (which comes from a functional programming perspective)?
- fizx 14y agoBecause otherwise you get a bunch of new Callable<Integer>() { @Override public call() { return 1; } }
- koide 14y agoBecause it's more expressive and leads to less and more maintainable code? Who cares about paradigm purity? Especially given on a language that's not totally pure already.
- joshAg 14y agoI don't care about paradigm purity, but given the amounts of java and lisp i've written, I didn't see why java would benefit from a lambda.
- masklinn 14y ago> why does a language designed around an OOP perspective need a lambda Because only through lambdas can you actually do OOP: a core of OOP is to tell objects to do things. That you can do with lambdas, through customizing "the thing". Without lambdas, you are left with the requirement to painfully and painstakingly get bits and pieces in or out of objects in order to do the thing yourself, ending up with a horrendously procedural language with a smattering of objects added on top. It's no secret — or mistake — that blocks are first-class components (and literals[0]) in the ur-OO language: http://en.wikipedia.org/wiki/Smalltalk#Code_blocks http://en.wikipedia.org/wiki/Smalltalk#Code_blocks (as well as http://en.wikipedia.org/wiki/Self_(programming_language) http://en.wikipedia.org/wiki/Self_(programming_language) ) [0] and really one of the few pieces of syntax
- fleitz 14y agoBecause lambdas offload programmer work to compilers. Think of a piece of code like: array = [1..10] evenNumbers = array.where(x => !(x % 2)) Now think of how to write that code not using lambdas. In Java where people seem to like typing unnecessary stuff it would make sense to not have lambdas as then you can type extra stuff. Also lambdas would reduce KLOCs thus making teams using java with lambdas less productive. This is similar to the reduced productivity seen by teams using scala or clojure on the JVM. Also, OOP has nothing to do with procedural or functional languages, it's completely orthogonal.
- rbanffy 14y agoActually, it needs pure functions. Lambdas are one way to add them with the benefit of being buzzword-compliant.