Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #3150 > unrolled thread
| Started by | Steve <tinker123@gmail.com> |
|---|---|
| First post | 2015-01-22 09:35 -0800 |
| Last post | 2015-01-23 22:17 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.java.help
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
| From | Steve <tinker123@gmail.com> |
|---|---|
| Date | 2015-01-22 09:35 -0800 |
| Subject | Lambdas/Callback Functions/Functional Programming. What is the point? |
| Message-ID | <d0ca87a6-bb4d-40ea-be51-4924c2368091@googlegroups.com> |
Hi all, I had my first introduction to Java 8 last night via a talk on lambdas, streams, and functional programming. I understand that this is they way college students are learning to program in Java, so it is here to stay, so I plan on learning it too. I want to understand why Oracle implemented lambdas, streams, and functional programming. It looks very similar to the "callback funcitons" I have seen in javascript and the jQuery library. I never liked that as it seemed to me to be a poor way of organizing things ( feeding blocks of code/functions into other functions ). Basically, what I would like to understand is what are the benefits of these things? Thanks Steve
[toc] | [next] | [standalone]
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Date | 2015-01-22 18:33 +0100 |
| Message-ID | <87ppa6u3d0.fsf@kuiper.lan.informatimago.com> |
| In reply to | #3150 |
Steve <tinker123@gmail.com> writes: > Hi all, > > I had my first introduction to Java 8 last night via a talk on > lambdas, streams, and functional programming. > > I understand that this is they way college students are learning to > program in Java, so it is here to stay, so I plan on learning it too. > > I want to understand why Oracle implemented lambdas, streams, and functional programming. > > It looks very similar to the "callback funcitons" I have seen in > javascript and the jQuery library. I never liked that as it seemed to > me to be a poor way of organizing things ( feeding blocks of > code/functions into other functions ). > > Basically, what I would like to understand is what are the benefits of these things? http://web.stanford.edu/class/cs242/readings/backus.pdf http://worrydream.com/refs/Hughes-WhyFunctionalProgrammingMatters.pdf -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
[toc] | [prev] | [next] | [standalone]
| From | Lothar Kimmeringer <news200709@kimmeringer.de> |
|---|---|
| Date | 2015-01-23 22:17 +0100 |
| Message-ID | <p6dpz2s3yh4e.dlg@kimmeringer.de> |
| In reply to | #3150 |
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 ---
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.help
csiph-web