anonymous classes versus lambda expression

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

anonymous classes versus lambda expression

Babak Vahdat
Hi

Would it make sense to you if we would change all the anonymous classes in Camel codebase to lambda expression where possible? Or any other idea you may have in this context?

Babak
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

omarsmak
It will pretty nice indeed to have a lambda instead of the anonymous
classes, not sure how much of the existing code will it break though.

On Fri, 11 Oct 2019 at 10:12, Babak Vahdat <[hidden email]>
wrote:

> Hi
>
> Would it make sense to you if we would change all the anonymous classes in
> Camel codebase to lambda expression where possible? Or any other idea you
> may have in this context?
>
> Babak
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

Zoran Regvart-2
In reply to this post by Babak Vahdat
Hi Babak,
I like lambdas as a concise way of writing callbacks and short
stateless functions. I have my IDE auto replace inner classes with
lambdas where applicable.

I wouldn't use them on hot paths as they incur a deeper stack. On hot
paths I'd prefer that we use stateless anonymous classes and avoid
allocating new instances if possible, i.e. cache them in a class
field.

Where possible we should annotate Camel public API with
@FunctionalInterface, to enable users to use them as they see fit.

2c

zoran

On Fri, Oct 11, 2019 at 10:12 AM Babak Vahdat
<[hidden email]> wrote:
>
> Hi
>
> Would it make sense to you if we would change all the anonymous classes in Camel codebase to lambda expression where possible? Or any other idea you may have in this context?
>
> Babak



--
Zoran Regvart
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

Babak Vahdat
Hi Zoran

Which IDE do you make use of? I tried it using eclipse which is a bit buggy and I had to manually fix a lot of changes it made by hand (I wish I had tried it with IntelliJ first). Currently more than 3K outgoing changes in my workspace with all tests & checkstyle rules passing locally.

I would provide a PR in case this effort should become concrete.

Babak

> On 11 Oct 2019, at 10:51, Zoran Regvart <[hidden email]> wrote:
>
> Hi Babak,
> I like lambdas as a concise way of writing callbacks and short
> stateless functions. I have my IDE auto replace inner classes with
> lambdas where applicable.
>
> I wouldn't use them on hot paths as they incur a deeper stack. On hot
> paths I'd prefer that we use stateless anonymous classes and avoid
> allocating new instances if possible, i.e. cache them in a class
> field.
>
> Where possible we should annotate Camel public API with
> @FunctionalInterface, to enable users to use them as they see fit.
>
> 2c
>
> zoran
>
> On Fri, Oct 11, 2019 at 10:12 AM Babak Vahdat
> <[hidden email]> wrote:
>>
>> Hi
>>
>> Would it make sense to you if we would change all the anonymous classes in Camel codebase to lambda expression where possible? Or any other idea you may have in this context?
>>
>> Babak
>
>
>
> --
> Zoran Regvart

Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

lburgazzoli
I would evaluate to replace anonymous classes with lambda as per case by
case as i.e. capturing lambdas may be a source of massive allocations, also
we need to take into account how they impact meta space allocations.

---
Luca Burgazzoli


On Fri, Oct 11, 2019 at 11:16 AM Babak Vahdat <[hidden email]>
wrote:

> Hi Zoran
>
> Which IDE do you make use of? I tried it using eclipse which is a bit
> buggy and I had to manually fix a lot of changes it made by hand (I wish I
> had tried it with IntelliJ first). Currently more than 3K outgoing changes
> in my workspace with all tests & checkstyle rules passing locally.
>
> I would provide a PR in case this effort should become concrete.
>
> Babak
>
> > On 11 Oct 2019, at 10:51, Zoran Regvart <[hidden email]> wrote:
> >
> > Hi Babak,
> > I like lambdas as a concise way of writing callbacks and short
> > stateless functions. I have my IDE auto replace inner classes with
> > lambdas where applicable.
> >
> > I wouldn't use them on hot paths as they incur a deeper stack. On hot
> > paths I'd prefer that we use stateless anonymous classes and avoid
> > allocating new instances if possible, i.e. cache them in a class
> > field.
> >
> > Where possible we should annotate Camel public API with
> > @FunctionalInterface, to enable users to use them as they see fit.
> >
> > 2c
> >
> > zoran
> >
> > On Fri, Oct 11, 2019 at 10:12 AM Babak Vahdat
> > <[hidden email]> wrote:
> >>
> >> Hi
> >>
> >> Would it make sense to you if we would change all the anonymous classes
> in Camel codebase to lambda expression where possible? Or any other idea
> you may have in this context?
> >>
> >> Babak
> >
> >
> >
> > --
> > Zoran Regvart
>
>
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

Claus Ibsen-2
On Fri, Oct 11, 2019 at 11:32 AM Luca Burgazzoli <[hidden email]> wrote:
>
> I would evaluate to replace anonymous classes with lambda as per case by
> case as i.e. capturing lambdas may be a source of massive allocations, also
> we need to take into account how they impact meta space allocations.
>

Yes be a bit careful with lambdas.
We did some optimisations on camel-core engine routing engine to
reduce some overheads with too many lamdas in the callstack.
That are internally faced.

However for end users then some places if its a single method
interface then marking them as @FunctionalInterface can aid the end
user API.




> ---
> Luca Burgazzoli
>
>
> On Fri, Oct 11, 2019 at 11:16 AM Babak Vahdat <[hidden email]>
> wrote:
>
> > Hi Zoran
> >
> > Which IDE do you make use of? I tried it using eclipse which is a bit
> > buggy and I had to manually fix a lot of changes it made by hand (I wish I
> > had tried it with IntelliJ first). Currently more than 3K outgoing changes
> > in my workspace with all tests & checkstyle rules passing locally.
> >
> > I would provide a PR in case this effort should become concrete.
> >
> > Babak
> >
> > > On 11 Oct 2019, at 10:51, Zoran Regvart <[hidden email]> wrote:
> > >
> > > Hi Babak,
> > > I like lambdas as a concise way of writing callbacks and short
> > > stateless functions. I have my IDE auto replace inner classes with
> > > lambdas where applicable.
> > >
> > > I wouldn't use them on hot paths as they incur a deeper stack. On hot
> > > paths I'd prefer that we use stateless anonymous classes and avoid
> > > allocating new instances if possible, i.e. cache them in a class
> > > field.
> > >
> > > Where possible we should annotate Camel public API with
> > > @FunctionalInterface, to enable users to use them as they see fit.
> > >
> > > 2c
> > >
> > > zoran
> > >
> > > On Fri, Oct 11, 2019 at 10:12 AM Babak Vahdat
> > > <[hidden email]> wrote:
> > >>
> > >> Hi
> > >>
> > >> Would it make sense to you if we would change all the anonymous classes
> > in Camel codebase to lambda expression where possible? Or any other idea
> > you may have in this context?
> > >>
> > >> Babak
> > >
> > >
> > >
> > > --
> > > Zoran Regvart
> >
> >



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

Claus Ibsen-2
In reply to this post by Babak Vahdat
On Fri, Oct 11, 2019 at 11:16 AM Babak Vahdat
<[hidden email]> wrote:
>
> Hi Zoran
>
> Which IDE do you make use of? I tried it using eclipse which is a bit buggy and I had to manually fix a lot of changes it made by hand (I wish I had tried it with IntelliJ first). Currently more than 3K outgoing changes in my workspace with all tests & checkstyle rules passing locally.
>

> I would provide a PR in case this effort should become concrete.
>

I would be a bit more careful with such a big change when we are
closing down on RC and GA release.

It also hurts backports to 2.x branches. However 2.x will become EOL
later in 2020 when we have released Camel 2.25 as the last 2.x, and
its last set of patch release.



> Babak
>
> > On 11 Oct 2019, at 10:51, Zoran Regvart <[hidden email]> wrote:
> >
> > Hi Babak,
> > I like lambdas as a concise way of writing callbacks and short
> > stateless functions. I have my IDE auto replace inner classes with
> > lambdas where applicable.
> >
> > I wouldn't use them on hot paths as they incur a deeper stack. On hot
> > paths I'd prefer that we use stateless anonymous classes and avoid
> > allocating new instances if possible, i.e. cache them in a class
> > field.
> >
> > Where possible we should annotate Camel public API with
> > @FunctionalInterface, to enable users to use them as they see fit.
> >
> > 2c
> >
> > zoran
> >
> > On Fri, Oct 11, 2019 at 10:12 AM Babak Vahdat
> > <[hidden email]> wrote:
> >>
> >> Hi
> >>
> >> Would it make sense to you if we would change all the anonymous classes in Camel codebase to lambda expression where possible? Or any other idea you may have in this context?
> >>
> >> Babak
> >
> >
> >
> > --
> > Zoran Regvart
>


--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

Andrea Cosentino-3
In reply to this post by Babak Vahdat
I don't think it is the best moment to do this while on RC sequence before
GA.

Il giorno ven 11 ott 2019 alle ore 10:12 Babak Vahdat <
[hidden email]> ha scritto:

> Hi
>
> Would it make sense to you if we would change all the anonymous classes in
> Camel codebase to lambda expression where possible? Or any other idea you
> may have in this context?
>
> Babak
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

Zoran Regvart-2
In reply to this post by Babak Vahdat
Hi Babak,

On Fri, Oct 11, 2019 at 11:16 AM Babak Vahdat
<[hidden email]> wrote:
> Which IDE do you make use of? I tried it using eclipse which is a bit buggy and I had to manually fix a lot of changes it made by hand (I wish I had tried it with IntelliJ first). Currently more than 3K outgoing changes in my workspace with all tests & checkstyle rules passing locally.

I unapologetically use Eclipse. I do update quite regularly...

zoran
--
Zoran Regvart
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes versus lambda expression

Babak Vahdat
In reply to this post by Claus Ibsen-2
Yeah you’re right. I had to ask in dev mailing list before starting with this task. My fault.

Babak

> On 11 Oct 2019, at 11:47, Claus Ibsen <[hidden email]> wrote:
>
> On Fri, Oct 11, 2019 at 11:32 AM Luca Burgazzoli <[hidden email] <mailto:[hidden email]>> wrote:
>>
>> I would evaluate to replace anonymous classes with lambda as per case by
>> case as i.e. capturing lambdas may be a source of massive allocations, also
>> we need to take into account how they impact meta space allocations.
>>
>
> Yes be a bit careful with lambdas.
> We did some optimisations on camel-core engine routing engine to
> reduce some overheads with too many lamdas in the callstack.
> That are internally faced.
>
> However for end users then some places if its a single method
> interface then marking them as @FunctionalInterface can aid the end
> user API.
>
>
>
>
>> ---
>> Luca Burgazzoli
>>
>>
>> On Fri, Oct 11, 2019 at 11:16 AM Babak Vahdat <[hidden email]>
>> wrote:
>>
>>> Hi Zoran
>>>
>>> Which IDE do you make use of? I tried it using eclipse which is a bit
>>> buggy and I had to manually fix a lot of changes it made by hand (I wish I
>>> had tried it with IntelliJ first). Currently more than 3K outgoing changes
>>> in my workspace with all tests & checkstyle rules passing locally.
>>>
>>> I would provide a PR in case this effort should become concrete.
>>>
>>> Babak
>>>
>>>> On 11 Oct 2019, at 10:51, Zoran Regvart <[hidden email]> wrote:
>>>>
>>>> Hi Babak,
>>>> I like lambdas as a concise way of writing callbacks and short
>>>> stateless functions. I have my IDE auto replace inner classes with
>>>> lambdas where applicable.
>>>>
>>>> I wouldn't use them on hot paths as they incur a deeper stack. On hot
>>>> paths I'd prefer that we use stateless anonymous classes and avoid
>>>> allocating new instances if possible, i.e. cache them in a class
>>>> field.
>>>>
>>>> Where possible we should annotate Camel public API with
>>>> @FunctionalInterface, to enable users to use them as they see fit.
>>>>
>>>> 2c
>>>>
>>>> zoran
>>>>
>>>> On Fri, Oct 11, 2019 at 10:12 AM Babak Vahdat
>>>> <[hidden email]> wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> Would it make sense to you if we would change all the anonymous classes
>>> in Camel codebase to lambda expression where possible? Or any other idea
>>> you may have in this context?
>>>>>
>>>>> Babak
>>>>
>>>>
>>>>
>>>> --
>>>> Zoran Regvart
>>>
>>>
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com <http://davsclaus.com/> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2 <https://www.manning.com/ibsen2>