Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #3152

Re: Lambdas/Callback Functions/Functional Programming. What is the point?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed1.swip.net!goblin3!goblin.stu.neva.ru!news.netfront.net!not-for-mail
From Lothar Kimmeringer <news200709@kimmeringer.de>
Newsgroups comp.lang.java.help
Subject Re: Lambdas/Callback Functions/Functional Programming. What is the point?
Date Fri, 23 Jan 2015 22:17:18 +0100
Organization Organization?! Only chaos here!
Lines 65
Message-ID <p6dpz2s3yh4e.dlg@kimmeringer.de> (permalink)
References <d0ca87a6-bb4d-40ea-be51-4924c2368091@googlegroups.com>
Reply-To news@kimmeringer.de
NNTP-Posting-Host 93.133.93.82
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding 7bit
X-Trace adenine.netfront.net 1422047837 10688 93.133.93.82 (23 Jan 2015 21:17:17 GMT)
X-Complaints-To news@netfront.net
NNTP-Posting-Date Fri, 23 Jan 2015 21:17:17 +0000 (UTC)
User-Agent 40tude_Dialog/2.0.15.1de
Xref csiph.com comp.lang.java.help:3152

Show key headers only | View raw


Steve wrote:

> I want to understand why Oracle implemented lambdas,
> streams, and functional programming.

One reason was, that everybody asked for this ;-)

> Basically, what I would like to understand is what are the
> benefits of these things?

One reason, why I waited so long for this is Delayed Initialization.
Resources are only created when they are necessary so instead
of all the repeated code like this:

public class HeavyResource {
  private ResourceData resData = null;

  public String getResourceResult() {
    if (resData == null){
      getResourceData();
    }
    return resData.getResult();
  }
}

you can now write

public class HeavyResouerce {
  private ResourceData resData = () -> getResourceData();

  public String getResourceResult() {
    return resData.getResult();
  }
}

The automatic creation if the resource hasn't been created
is done the moment the first access takes place to it. And
it is done in a thread-safe way (that many self made solutions
often fail to implement correctly)

Another feature is Lazy Evaluation. If you call a method
evaluate(heavyCalc1(), heavyCalc(2))
both heavyCalc-methods are called before the call of evaluate.
If the result of heavyCalc1 is enough for the evaluation the
call of heavyCalc2 was useless. Simple real-world-example:
logDebug(callStatusWebService());

With Lazy Evaluation the methods in the parameters are only
called if they are actually needed in the method.

A third feature is the ability to parallelize streams.
Just call .parallelStream instead of .stream and your
whole operation will be performed on all available CPUs
instead of only one.


Best regards, Lothar
-- 
Lothar Kimmeringer                E-Mail: spamfang@kimmeringer.de
               PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
                 questions!

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Back to comp.lang.java.help | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Lambdas/Callback Functions/Functional Programming.  What is the point? Steve <tinker123@gmail.com> - 2015-01-22 09:35 -0800
  Re: Lambdas/Callback Functions/Functional Programming.  What is the point? "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-01-22 18:33 +0100
  Re: Lambdas/Callback Functions/Functional Programming.  What is the point? Lothar Kimmeringer <news200709@kimmeringer.de> - 2015-01-23 22:17 +0100

csiph-web