Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Why is that in JDK8: value used in lambda expression shuld beeffectively final?

Reply
Thread Tools

Why is that in JDK8: value used in lambda expression shuld beeffectively final?

 
 
Arved Sandstrom
Guest
Posts: n/a
 
      01-03-2013
On 01/02/2013 04:52 PM, Lew wrote:
> Saxo wrote:
>> So free variables aren't possible with JDK8 lambdas. For people used to closures, this is surely
>> surprising. Well, this does not render JDK8 lambdas useless. On the contrary, an imense amount of
>> boilerplate code that is necessary without them can be removed with them. Once the JDK8 gets
>> released this will be an eye-opener to
>> about 95% of all Java developers (the ratio of Java developers not understanding closures ...).

>
> The ratio of Java developers who do not understand closures is probably pretty close to the
> ratio of Java developers who do not understand Java.

[ SNIP ]

I don't get that statement at all. A significant percentage of Java
programmers don't use any other languages in a big way, including those
that do have closures. And since Java itself doesn't have them (*), I
just don't see why a programmer who understand Java really well can't
also *not* know about closures.

AHS

* I'll wager that a lot of Java programmers - the ones with their hands
full still doing their production work in JDK 1.6 and 1.7, say, don't
have time to play with experimental features.
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      01-03-2013
Steven Simpson wrote:
> Saxo wrote:
>>> int sum = ints.reduce(0, (x, y) -> x + y);

>
>> Nice, but it does not compile with me. I use IDEA 12 and the
>> lambda-8-b69-windows-i586-17_dec_2012 JDK. Seems like reduce does not exist in
>> Iterator or Collection!?

>
> I figured, if forEach is on Collection, reduce likely would be too. I


'forEach' is not on Collection. It's on Collection's parent type.

> did try to have a look for it in source, but wasn't sure if I had the
> right branch. I also didn't find the javadoc on-line. Based on the
> source, try:


Javadoc for Java 8 is on line:
http://download.java.net/jdk8/docs/api/index.html

Not hard to find, but it doesn't contain the information you wanted.


> ints.stream().reduce(0, (x, y) -> x + y)


http://datumedge.blogspot.com/2012/0...8-lambdas.html
gives a brief overview.

--
Lew
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      01-03-2013
Arved Sandstrom wrote:
> Lew wrote:
>> Saxo wrote:
>>> So free variables aren't possible with JDK8 lambdas. For people used to closures, this is surely
>>> surprising. Well, this does not render JDK8 lambdas useless. On the contrary, an imense amount of
>>> boilerplate code that is necessary without them can be removed with them. Once the JDK8 gets
>>> released this will be an eye-opener to
>>> about 95% of all Java developers (the ratio of Java developers not understanding closures ...).

>
>> The ratio of Java developers who do not understand closures is probably pretty close to the
>> ratio of Java developers who do not understand Java.

>
> [ SNIP ]


>
> I don't get that statement at all. A significant percentage of Java


You mean you don't agree with it. Apparently you do get it.

> programmers don't use any other languages in a big way, including those


How significant? What percentage? Aren't these the same ones I said don't understand
Java either?

How do you know they aren't?

> that do have closures. And since Java itself doesn't have them (*), I
> just don't see why a programmer who understand Java really well can't
> also *not* know about closures.


Can, certainly. But the statement was statistical, not possibilistic.

Where does "95%" come from? Where does "significant percentage" come from?

My point is that there are no data for these assertions. Likewise, I have no data, but
unless you do you have nothing with which to refute my assertion.

Plus there's the aforementioned matter of agreeing on definitions.
>
> * I'll wager that a lot of Java programmers - the ones with their hands


How much is "a lot"? Does it approach 95%?

> full still doing their production work in JDK 1.6 and 1.7, say, don't
> have time to play with experimental features.


I have my hands full doing production work in JDK 1.6 and 1.7. Yet I do play with
experimental features, and even read about them beyond that.

Doesn't everyone? Don't you?

Anyone who doesn't, doesn't understand Java.

--
Lew

 
Reply With Quote
 
Saxo
Guest
Posts: n/a
 
      01-03-2013
> Aside from that your comment is unsupportable. Or do you have evidence?

What I mean is that almost every Java developer I met during the last 10 years didn't know what I meant when I said it's a pitty that Java does not have closures. I can't remember anyone who asked anything else in return than"and what are closures?". Having worked some of these years as a consultant I did see places. Almost nobody are those famous 95%. Funny that people get that annoyed. For the older guys that have worked with some other language than Java before the difference f.ex. between Smalltalk developers and Java developers is striking in terms of intellectual reflection, general interest, etc. Probably a good place to be nowadays is the people from the Scala camp.

-- Oliver
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      01-03-2013
Saxo <(E-Mail Removed)> writes:
>What I mean is that almost every Java developer I met during
>the last 10 years didn't know what I meant when I said it's a
>pitty that Java does not have closures.


Clojure already exists, and everyone who wants to program
the LISP style is free to choose LISP or Clojure.

Using LISP style in Java is not necessarily good Java style!

For a Java programmer, good knowledge of Java is already
sufficient. He does not need to know terminology of other
languages!

»Almost every English speaker I met didn't know what I
meant, when I said it's a pitty that English does not
have an ablative.«

What in LISP is expressed by creating a new closure, in Java
can be expressed by creating a new instance of a class.

( SETQ ADDER( LAMBDA( N )( LAMBDA( X )( + X N ))))

becomes

public class Adder
{ private final int n;
public Adder( final int n ){ this.n = n; }
public int add( final int x ){ return x + this.n; }}

 
Reply With Quote
 
Saxo
Guest
Posts: n/a
 
      01-03-2013
Am Mittwoch, 2. Januar 2013 22:46:00 UTC+1 schrieb Steven Simpson:
> ints.stream().reduce(0, (x, y) -> x + y)


This did it . Thanks, good to know.
 
Reply With Quote
 
Saxo
Guest
Posts: n/a
 
      01-03-2013
I wrote a little blog post about the matter to sum it up:

http://objectscape.blogspot.de/2013/...ictive-as.html

Hope it is enjoyable
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-03-2013
Patricia Shanahan wrote:
> Stefan Ram wrote:
>> Saxo writes:
>>> What I mean is that almost every Java developer I met during
>>> the last 10 years didn't know what I meant when I said it's a
>>> pitty that Java does not have closures.


On this newsgroup there've been spirited discussions on this topic for years.

In my experience over the last ten years lots and lots of Java programmers, most
of the ones with whom I've spoken, knew what closures were if they were reasonably
competent Java programmers.

But I don't claim statistical significance for my non-random idiosyncratic sample.
You should not either.

The fact that my experience is the opposite of yours should be evidence for that.

For the record, I argued vehemently against the addition of closures to Java.

I tend to agree with Stefan here.

>> Clojure already exists, and everyone who wants to program
>> the LISP style is free to choose LISP or Clojure.

>
>> Using LISP style in Java is not necessarily good Java style!

>
>> For a Java programmer, good knowledge of Java is already
>> sufficient. He does not need to know terminology of other
>> languages!


Wrong.

> ...
> I would distinguish different levels of programming skill. If one is
> going to be making decisions such as choosing the language for a
> project, it is important to understand the capabilities and supported
> programming styles for a wide variety of languages.
>
> Similarly, anyone working in programming language design and
> standardization should understand the possibilities that have been
> demonstrated by other languages.
>
> For someone who is just programming in one language, it is enough to
> know that language well.


Wrong.

It is not enough.

Because people who learn only Java tend not to even program Java well.

That I've seen. I don't know if that has statistical significance.

But based on my experience and much reading and the advice of mentors,
I will state unequivocally that knowledge of only Java makes a terrible computer
programmer.

Simply terrible.

Any real programmer would have learned at *least* one other language, usually
prior to learning Java, and would understand things like computable pointers.

Anyone who calls themselves a programmer and is unwilling to learn a second programming
language is an ass and needs to switch to serving fries to fast-food customers.

--
Lew
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      01-04-2013
On 01/02/2013 09:40 PM, Lew wrote:
> Arved Sandstrom wrote:
>> Lew wrote:
>>> Saxo wrote:
>>>> So free variables aren't possible with JDK8 lambdas. For people used to closures, this is surely
>>>> surprising. Well, this does not render JDK8 lambdas useless. On the contrary, an imense amount of
>>>> boilerplate code that is necessary without them can be removed with them. Once the JDK8 gets
>>>> released this will be an eye-opener to
>>>> about 95% of all Java developers (the ratio of Java developers not understanding closures ...).

>>
>>> The ratio of Java developers who do not understand closures is probably pretty close to the
>>> ratio of Java developers who do not understand Java.

>>
>> [ SNIP ]

>
>>
>> I don't get that statement at all. A significant percentage of Java

>
> You mean you don't agree with it. Apparently you do get it.
>
>> programmers don't use any other languages in a big way, including those

>
> How significant? What percentage? Aren't these the same ones I said don't understand
> Java either?
>
> How do you know they aren't?
>
>> that do have closures. And since Java itself doesn't have them (*), I
>> just don't see why a programmer who understand Java really well can't
>> also *not* know about closures.

>
> Can, certainly. But the statement was statistical, not possibilistic.
>
> Where does "95%" come from? Where does "significant percentage" come from?
>
> My point is that there are no data for these assertions. Likewise, I have no data, but
> unless you do you have nothing with which to refute my assertion.
>
> Plus there's the aforementioned matter of agreeing on definitions.
>>
>> * I'll wager that a lot of Java programmers - the ones with their hands

>
> How much is "a lot"? Does it approach 95%?
>
>> full still doing their production work in JDK 1.6 and 1.7, say, don't
>> have time to play with experimental features.

>
> I have my hands full doing production work in JDK 1.6 and 1.7. Yet I do play with
> experimental features, and even read about them beyond that.
>
> Doesn't everyone? Don't you?
>
> Anyone who doesn't, doesn't understand Java.
>

Well, we can agree on one thing - absent hard numbers - which I'm not
sure exist - none of us have more than anecdotes.

I'll say this - I've worked closely with hundreds of programmers over my
career. Not just Java, obviously, everything under the sun. I've
interviewed many dozens of developers. I've seen a humungous amount of
code written by other people. I read professionally voraciously.

These same statements are probably applicable to you and a bunch of
other people in this NG too.

_My_ takeaway from all that is that most professional working
programmers are M-F 9-5. They don't actually spend time at home coding
or doing professional development (with the exception of training or
reading books that help them with the immediate technologies that they
need *now*). They don't have more than an above-average grasp of
anything, they aren't even that interested in the field.

So no, I don't believe for a second that more than 5 or 10 percent of
coders play with experimental features or learn languages that they may
never use on the job...let alone teach themselves CS underpinnings of
what they do.

But this is all anecdotal. You may have all your career worked with
young hard-chargers who absolutely live to code. You'd see things
differently.

As for *me*, the new _language_ features in Java 7 don't exactly take
more than a few hours to read about and trial out in a simple test
program. I spent rather more time investigating the new APIs in 7, so I
know what's there and can plan to use it if appropriate.

As for what is coming out in 8, I could not care less. I really could
not. I'm not using 8 yet, and none of my Java work (which these days is
a small bit of what I do) will even be on the Java 8 platform for years.
So why waste my time? I'd rather hone up on Scala, Clojure, latest C#,
and F#...to name a few.

AHS
 
Reply With Quote
 
Steven Simpson
Guest
Posts: n/a
 
      01-04-2013
On 03/01/13 14:45, Saxo wrote:
> http://objectscape.blogspot.de/2013/...ictive-as.html


I'm still interested in seeing an example that you would normally write
with free variables, demonstrating that lambdas are inadequate for the
things you'd like to do. The example you provided of summing integers
has two alternatives, so it only serves to show that free variables are
not possible, not that free variables are necessary.

Can you contrive something more sophisticated, as an exercise?

--
ss at comp dot lancs dot ac dot uk

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
lambda vs non-lambda proc Steve Dogers Ruby 1 03-30-2009 10:11 PM
I have an examination and i shuld answer this question please help me omid1980@gmail.com XML 1 02-18-2007 10:24 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Re: Lambda as declarative idiom (was RE: what is lambda used for inreal code?) Roman Suzi Python 13 01-07-2005 09:33 PM



Advertisments