Is a a good idea to retrofit all foreach loop to use lambda ? Was: Checked exceptions within Block<T>
Remi Forax
forax at univ-mlv.fr
Sun Jan 13 02:29:21 PST 2013
On 01/13/2013 10:22 AM, Michael Hixson wrote:
> Hi Remi,
>
> When you say this, you're talking about the generic Iterable.forEach
> that defaults to "for (foo bar : baz)" implementation, right? You're
> not talking about overridden implementations like ArrayList.forEach or
> Stream.forEach (for the streams returned by the current library)?
yes, overridden implementations can be faster or not.
If you have a code that already exists, retrofitting it will change the
perf of your application, for better or worse. It's not like adding
generics by example that was a mostly binary compatible transformation.
I think it's simpler to first uses lambda in new code, enjoy it's
conciseness and learn from that before retrofitting already existing codes.
>
> -Michael
cheers,
Rémi
>
> On Sat, Jan 12, 2013 at 11:04 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>> On 01/12/2013 05:12 AM, Michael Hixson wrote:
>>> An issue that came up repeatedly was that I wanted refactor code like this:
>>>
>>> for (Value value : values) {
>>> ...
>>> }
>>>
>>> Into this:
>>>
>>> values.forEach(value -> {
>>> ...
>>> });
>> hijacking this thread...
>>
>> Blindly retrofitting all foreach loops to use lambda instead will cause
>> you some perf trouble,
>> because the VM JIT is currently not as good as optimizing lambda calls
>> as it optimizes loops.
>>
>> If you have few elements (<10 000) you should not care because otherwise,
>> it's better to keep the good old for each loop, at least for now.
>>
>> cheers,
>> Rémi
>>
>>
>>
>>
>>
More information about the lambda-dev
mailing list