Fwd: lambda expression parameters
Paul Benedict
pbenedict at apache.org
Tue Dec 18 15:24:46 PST 2012
I agree with Remi 100%. I actually had to throw away two email drafts
and wait -- I knew he would articulate it better than myself. :-) If
lambda parameters become immutable, they will surely become a great
"gotcha" question on the next OCP Java exam. I think we leave things
as they are so it's easy for Junior Joe Developer to know there aren't
magic rules coming into play simply because of the syntax.
Paul
On Tue, Dec 18, 2012 at 5:09 PM, Remi Forax <forax at univ-mlv.fr> wrote:
> On 12/18/2012 11:51 PM, Brian Goetz wrote:
>>
>> Imagine we were designing a language from scratch, knowing what we have
>> learned in the last 17 years about mutability being the root of all evil.
>> We would do many things to gently encourage people away from avoidable
>> mutability.
>
>
> sorry, side effects are the root of all evil.
>
>>
>> Of all places to additionally discourage mutability as a way to do things,
>> and where it would likely have the least harm,
>
>
> I don't like cargo cult.
>
>> lambda parameters seem an obvious choice.
>
>
> and as I said, it doesn't worth the pain for people to understand why it
> works with methods and not with lambda.
>
>> The only reason we'd even consider letting them be mutable is that Java
>> already has methods that have parameters that are mutable by default, and
>> lambdas are like methods.
>
>
> lambdas are anonymous methods, simple to explain, simple to understand,
> but wait, the scoping rules ...
>
> Rémi
>
>>
>> On 12/18/2012 5:41 PM, Remi Forax wrote:
>>>
>>> On 12/18/2012 11:33 PM, Brian Goetz wrote:
>>>>
>>>> I like this suggestion that Venkat made on lambda-dev. However, it
>>>> would have to be a little more restrictive than that; basically, that
>>>> lambda parameters are *always* final. The only thing where I can
>>>> imagine this being an issue is in refactoring from inner classes, and
>>>> even there, if you are modifying method parameters, it is likely that
>>>> you need to do additional work to adapt this inner class to a lambda
>>>> anyway.
>>>>
>>>> So the suggestion is: lambda formals are always final.
>>>>
>>>> What do people think?
>>>
>>>
>>> Brian,
>>> I don't see why parameter should be final. You explain a reason why they
>>> should not, but not why they should.
>>>
>>> Rémi
>>>
>>>>
>>>>
>>>> -------- Original Message --------
>>>> Subject: lambda expression parameters
>>>> Date: Tue, 18 Dec 2012 14:40:25 -0700
>>>> From: Venkat Subramaniam <venkats at agiledeveloper.com>
>>>> To: lambda-dev at openjdk.java.net <lambda-dev at openjdk.java.net>
>>>>
>>>> Hi
>>>>
>>>> Is there plans to make the inferred parameter of a lambda expression
>>>> final by default.
>>>> Right now, we can't specify the parameter is final unless we provide
>>>> it with the type.
>>>>
>>>> In the spirit of leaning towards immutability, which is a better
>>>> practice, would it be possible to
>>>>
>>>> (a) make all inferred parameters of lambda expressions final, and
>>>> (b) to make it non-final, force the developers to explicitly request
>>>> (like the mutable in F#).
>>>>
>>>> It's more of a wish-list, if that's something that can be considered.
>>>>
>>>> Thanks,
>>>>
>>>> Venkat
>>>>
>>>>
>>>>
>>>
>
More information about the lambda-spec-observers
mailing list