You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martin Grigorov <mg...@apache.org> on 2014/01/31 15:08:21 UTC

Method chaining

Hi,

What others think about https://issues.apache.org/jira/browse/WICKET-5459 ?
Should Wicket use "return this" pattern where makes sense instead of 'void'
return type ?

One problem that I see is with:
MyPage.doSomething() will/may return some base type of MyPage.
I remember some trink for Java to make this simpler but AFAIR it involved
some longer generics signature for the class that use it.



Martin Grigorov
Wicket Training and Consulting

Re: Method chaining

Posted by Martin Grigorov <mg...@apache.org>.
A place where method chaining would be good to have is in all XyzSettings
classes.

Martin Grigorov
Wicket Training and Consulting


On Fri, Jan 31, 2014 at 4:45 PM, Nick Pratt <nb...@gmail.com> wrote:

> Just to be clear - I'm not arguing against the concept of method chaining
> because of some stylistic / personal preference point, but from a practical
> production diagnostic point, when you need to be able to definitively fix
> the problem once, and once only. Pushing a temporary release out with
> additional logging (or breaking apart a method chain into separate method
> calls per line) that will assist you the *next* time the bug happens just
> isn't acceptable to some businesses - something I don't disagree with. It's
> for this reason, and this reason only, that we don't use method chaining.
> It's purely risk mitigation.
>
> I logged the RFE with Oracle - who knows if I'm the first to log such a
> request, or whether anything will come of it.
>
> For comparison, look at the stack trace output from a simple C# program.
>
> Regards
>
> Nick
>
>
> On Fri, Jan 31, 2014 at 10:37 AM, tetsuo <ro...@gmail.com> wrote:
>
> > Making 'void' methods return 'this' doesn't prevent you to write each
> call
> > in a new line. But gives others the choice to call it inline.
> >
> > It could be a problem if Wicket's internal code used chaining
> extensively,
> > but I find it very convenient to chain calls, specially when building the
> > component tree for a page. If you break lines in the right places,
> Eclipse
> > indents it beautifully, if configured to not automatically join lines.
> >
> > I'd love to see this adopted throughout the API, but it will break
> > compatibility everywhere you override these void methods (not if you just
> > use them). Which is much less than other kinds of change, but still... I
> > really like backwards compatibility :)
> >
> >
> >
> >
> >
> >
> > On Fri, Jan 31, 2014 at 1:15 PM, Nick Pratt <nb...@gmail.com> wrote:
> >
> > > Which would be perfectly fine if the JVM told you which specific method
> > > invocation on a source code line with chained methods threw an
> exception.
> > >  While you can sometimes figure it out, you can't always, and an answer
> > of
> > > "if it happens again, we'll know how to fix it" just doesn't fly in
> > certain
> > > verticals.
> > >
> > > For our production code we don't allow it, and we strongly recommend
> that
> > > our clients don't use it either.
> > >
> > > Perhaps I should log a RFE with Oracle.
> > >
> > > N
> > >
> > >
> > > On Fri, Jan 31, 2014 at 9:32 AM, Martin Makundi <
> > > martin.makundi@koodaripalvelut.com> wrote:
> > >
> > > > Java should natively chain all void instance methods...
> > > >
> > > > **
> > > > Martin
> > > >
> > > >
> > > > 2014-01-31 Sven Meier <sv...@meiers.net>
> > > >
> > > > > I don't think it makes sense here:
> > > > > In all of Wicket's code there's a single place only, where two
> > metaData
> > > > > entries are set consecutively.
> > > > >
> > > > > Sven
> > > > >
> > > > >
> > > > > On 01/31/2014 03:08 PM, Martin Grigorov wrote:
> > > > >
> > > > >> Hi,
> > > > >>
> > > > >> What others think about
> > > > https://issues.apache.org/jira/browse/WICKET-5459?
> > > > >> Should Wicket use "return this" pattern where makes sense instead
> of
> > > > >> 'void'
> > > > >> return type ?
> > > > >>
> > > > >> One problem that I see is with:
> > > > >> MyPage.doSomething() will/may return some base type of MyPage.
> > > > >> I remember some trink for Java to make this simpler but AFAIR it
> > > > involved
> > > > >> some longer generics signature for the class that use it.
> > > > >>
> > > > >>
> > > > >>
> > > > >> Martin Grigorov
> > > > >> Wicket Training and Consulting
> > > > >>
> > > > >>
> > > > >
> > > >
> > >
> >
>

Re: Method chaining

Posted by Nick Pratt <nb...@gmail.com>.
Just to be clear - I'm not arguing against the concept of method chaining
because of some stylistic / personal preference point, but from a practical
production diagnostic point, when you need to be able to definitively fix
the problem once, and once only. Pushing a temporary release out with
additional logging (or breaking apart a method chain into separate method
calls per line) that will assist you the *next* time the bug happens just
isn't acceptable to some businesses - something I don't disagree with. It's
for this reason, and this reason only, that we don't use method chaining.
It's purely risk mitigation.

I logged the RFE with Oracle - who knows if I'm the first to log such a
request, or whether anything will come of it.

For comparison, look at the stack trace output from a simple C# program.

Regards

Nick


On Fri, Jan 31, 2014 at 10:37 AM, tetsuo <ro...@gmail.com> wrote:

> Making 'void' methods return 'this' doesn't prevent you to write each call
> in a new line. But gives others the choice to call it inline.
>
> It could be a problem if Wicket's internal code used chaining extensively,
> but I find it very convenient to chain calls, specially when building the
> component tree for a page. If you break lines in the right places, Eclipse
> indents it beautifully, if configured to not automatically join lines.
>
> I'd love to see this adopted throughout the API, but it will break
> compatibility everywhere you override these void methods (not if you just
> use them). Which is much less than other kinds of change, but still... I
> really like backwards compatibility :)
>
>
>
>
>
>
> On Fri, Jan 31, 2014 at 1:15 PM, Nick Pratt <nb...@gmail.com> wrote:
>
> > Which would be perfectly fine if the JVM told you which specific method
> > invocation on a source code line with chained methods threw an exception.
> >  While you can sometimes figure it out, you can't always, and an answer
> of
> > "if it happens again, we'll know how to fix it" just doesn't fly in
> certain
> > verticals.
> >
> > For our production code we don't allow it, and we strongly recommend that
> > our clients don't use it either.
> >
> > Perhaps I should log a RFE with Oracle.
> >
> > N
> >
> >
> > On Fri, Jan 31, 2014 at 9:32 AM, Martin Makundi <
> > martin.makundi@koodaripalvelut.com> wrote:
> >
> > > Java should natively chain all void instance methods...
> > >
> > > **
> > > Martin
> > >
> > >
> > > 2014-01-31 Sven Meier <sv...@meiers.net>
> > >
> > > > I don't think it makes sense here:
> > > > In all of Wicket's code there's a single place only, where two
> metaData
> > > > entries are set consecutively.
> > > >
> > > > Sven
> > > >
> > > >
> > > > On 01/31/2014 03:08 PM, Martin Grigorov wrote:
> > > >
> > > >> Hi,
> > > >>
> > > >> What others think about
> > > https://issues.apache.org/jira/browse/WICKET-5459?
> > > >> Should Wicket use "return this" pattern where makes sense instead of
> > > >> 'void'
> > > >> return type ?
> > > >>
> > > >> One problem that I see is with:
> > > >> MyPage.doSomething() will/may return some base type of MyPage.
> > > >> I remember some trink for Java to make this simpler but AFAIR it
> > > involved
> > > >> some longer generics signature for the class that use it.
> > > >>
> > > >>
> > > >>
> > > >> Martin Grigorov
> > > >> Wicket Training and Consulting
> > > >>
> > > >>
> > > >
> > >
> >
>

Re: Method chaining

Posted by tetsuo <ro...@gmail.com>.
Making 'void' methods return 'this' doesn't prevent you to write each call
in a new line. But gives others the choice to call it inline.

It could be a problem if Wicket's internal code used chaining extensively,
but I find it very convenient to chain calls, specially when building the
component tree for a page. If you break lines in the right places, Eclipse
indents it beautifully, if configured to not automatically join lines.

I'd love to see this adopted throughout the API, but it will break
compatibility everywhere you override these void methods (not if you just
use them). Which is much less than other kinds of change, but still... I
really like backwards compatibility :)






On Fri, Jan 31, 2014 at 1:15 PM, Nick Pratt <nb...@gmail.com> wrote:

> Which would be perfectly fine if the JVM told you which specific method
> invocation on a source code line with chained methods threw an exception.
>  While you can sometimes figure it out, you can't always, and an answer of
> "if it happens again, we'll know how to fix it" just doesn't fly in certain
> verticals.
>
> For our production code we don't allow it, and we strongly recommend that
> our clients don't use it either.
>
> Perhaps I should log a RFE with Oracle.
>
> N
>
>
> On Fri, Jan 31, 2014 at 9:32 AM, Martin Makundi <
> martin.makundi@koodaripalvelut.com> wrote:
>
> > Java should natively chain all void instance methods...
> >
> > **
> > Martin
> >
> >
> > 2014-01-31 Sven Meier <sv...@meiers.net>
> >
> > > I don't think it makes sense here:
> > > In all of Wicket's code there's a single place only, where two metaData
> > > entries are set consecutively.
> > >
> > > Sven
> > >
> > >
> > > On 01/31/2014 03:08 PM, Martin Grigorov wrote:
> > >
> > >> Hi,
> > >>
> > >> What others think about
> > https://issues.apache.org/jira/browse/WICKET-5459?
> > >> Should Wicket use "return this" pattern where makes sense instead of
> > >> 'void'
> > >> return type ?
> > >>
> > >> One problem that I see is with:
> > >> MyPage.doSomething() will/may return some base type of MyPage.
> > >> I remember some trink for Java to make this simpler but AFAIR it
> > involved
> > >> some longer generics signature for the class that use it.
> > >>
> > >>
> > >>
> > >> Martin Grigorov
> > >> Wicket Training and Consulting
> > >>
> > >>
> > >
> >
>

Re: Method chaining

Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Jan 31, 2014 at 4:15 PM, Nick Pratt <nb...@gmail.com> wrote:

> Which would be perfectly fine if the JVM told you which specific method
> invocation on a source code line with chained methods threw an exception.
>  While you can sometimes figure it out, you can't always, and an answer of
> "if it happens again, we'll know how to fix it" just doesn't fly in certain
> verticals.
>
> For our production code we don't allow it, and we strongly recommend that
> our clients don't use it either.
>
> Perhaps I should log a RFE with Oracle.
>

Well, this is matter of personal preference how to style your code.
Nothing stops you to do:

  instance.abc(); instance.def()

in one line!
No method chaining here but again hard to find which method blowed ...


>
> N
>
>
> On Fri, Jan 31, 2014 at 9:32 AM, Martin Makundi <
> martin.makundi@koodaripalvelut.com> wrote:
>
> > Java should natively chain all void instance methods...
> >
> > **
> > Martin
> >
> >
> > 2014-01-31 Sven Meier <sv...@meiers.net>
> >
> > > I don't think it makes sense here:
> > > In all of Wicket's code there's a single place only, where two metaData
> > > entries are set consecutively.
> > >
> > > Sven
> > >
> > >
> > > On 01/31/2014 03:08 PM, Martin Grigorov wrote:
> > >
> > >> Hi,
> > >>
> > >> What others think about
> > https://issues.apache.org/jira/browse/WICKET-5459?
> > >> Should Wicket use "return this" pattern where makes sense instead of
> > >> 'void'
> > >> return type ?
> > >>
> > >> One problem that I see is with:
> > >> MyPage.doSomething() will/may return some base type of MyPage.
> > >> I remember some trink for Java to make this simpler but AFAIR it
> > involved
> > >> some longer generics signature for the class that use it.
> > >>
> > >>
> > >>
> > >> Martin Grigorov
> > >> Wicket Training and Consulting
> > >>
> > >>
> > >
> >
>

Re: Method chaining

Posted by Nick Pratt <nb...@gmail.com>.
Which would be perfectly fine if the JVM told you which specific method
invocation on a source code line with chained methods threw an exception.
 While you can sometimes figure it out, you can't always, and an answer of
"if it happens again, we'll know how to fix it" just doesn't fly in certain
verticals.

For our production code we don't allow it, and we strongly recommend that
our clients don't use it either.

Perhaps I should log a RFE with Oracle.

N


On Fri, Jan 31, 2014 at 9:32 AM, Martin Makundi <
martin.makundi@koodaripalvelut.com> wrote:

> Java should natively chain all void instance methods...
>
> **
> Martin
>
>
> 2014-01-31 Sven Meier <sv...@meiers.net>
>
> > I don't think it makes sense here:
> > In all of Wicket's code there's a single place only, where two metaData
> > entries are set consecutively.
> >
> > Sven
> >
> >
> > On 01/31/2014 03:08 PM, Martin Grigorov wrote:
> >
> >> Hi,
> >>
> >> What others think about
> https://issues.apache.org/jira/browse/WICKET-5459?
> >> Should Wicket use "return this" pattern where makes sense instead of
> >> 'void'
> >> return type ?
> >>
> >> One problem that I see is with:
> >> MyPage.doSomething() will/may return some base type of MyPage.
> >> I remember some trink for Java to make this simpler but AFAIR it
> involved
> >> some longer generics signature for the class that use it.
> >>
> >>
> >>
> >> Martin Grigorov
> >> Wicket Training and Consulting
> >>
> >>
> >
>

Re: Method chaining

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Java should natively chain all void instance methods...

**
Martin


2014-01-31 Sven Meier <sv...@meiers.net>

> I don't think it makes sense here:
> In all of Wicket's code there's a single place only, where two metaData
> entries are set consecutively.
>
> Sven
>
>
> On 01/31/2014 03:08 PM, Martin Grigorov wrote:
>
>> Hi,
>>
>> What others think about https://issues.apache.org/jira/browse/WICKET-5459?
>> Should Wicket use "return this" pattern where makes sense instead of
>> 'void'
>> return type ?
>>
>> One problem that I see is with:
>> MyPage.doSomething() will/may return some base type of MyPage.
>> I remember some trink for Java to make this simpler but AFAIR it involved
>> some longer generics signature for the class that use it.
>>
>>
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>>
>>
>

Re: Method chaining

Posted by Martin Grigorov <mg...@apache.org>.
I ask generally, not just about #setMetaData().
For example:
someComponent.add(behavior).add(child).setVisible(false).setEnabled(false).setMetaData(..)
...
And not just about Component class but "everywhere where it makes sense".

Martin Grigorov
Wicket Training and Consulting


On Fri, Jan 31, 2014 at 3:25 PM, Sven Meier <sv...@meiers.net> wrote:

> I don't think it makes sense here:
> In all of Wicket's code there's a single place only, where two metaData
> entries are set consecutively.
>
> Sven
>
>
> On 01/31/2014 03:08 PM, Martin Grigorov wrote:
>
>> Hi,
>>
>> What others think about https://issues.apache.org/jira/browse/WICKET-5459?
>> Should Wicket use "return this" pattern where makes sense instead of
>> 'void'
>> return type ?
>>
>> One problem that I see is with:
>> MyPage.doSomething() will/may return some base type of MyPage.
>> I remember some trink for Java to make this simpler but AFAIR it involved
>> some longer generics signature for the class that use it.
>>
>>
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>>
>>
>

Re: Method chaining

Posted by Sven Meier <sv...@meiers.net>.
I don't think it makes sense here:
In all of Wicket's code there's a single place only, where two metaData 
entries are set consecutively.

Sven

On 01/31/2014 03:08 PM, Martin Grigorov wrote:
> Hi,
>
> What others think about https://issues.apache.org/jira/browse/WICKET-5459 ?
> Should Wicket use "return this" pattern where makes sense instead of 'void'
> return type ?
>
> One problem that I see is with:
> MyPage.doSomething() will/may return some base type of MyPage.
> I remember some trink for Java to make this simpler but AFAIR it involved
> some longer generics signature for the class that use it.
>
>
>
> Martin Grigorov
> Wicket Training and Consulting
>


Re: Method chaining

Posted by Rob Audenaerde <ro...@gmail.com>.
I like chaining for instances. I don't see much use for chaining in static
methods.


On Fri, Jan 31, 2014 at 3:12 PM, Maxim Solodovnik <so...@gmail.com>wrote:

> I personally like chaining in Wicket
>
>
> On Fri, Jan 31, 2014 at 9:08 PM, Martin Grigorov <mgrigorov@apache.org
> >wrote:
>
> > Hi,
> >
> > What others think about
> https://issues.apache.org/jira/browse/WICKET-5459?
> > Should Wicket use "return this" pattern where makes sense instead of
> 'void'
> > return type ?
> >
> > One problem that I see is with:
> > MyPage.doSomething() will/may return some base type of MyPage.
> > I remember some trink for Java to make this simpler but AFAIR it involved
> > some longer generics signature for the class that use it.
> >
> >
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> >
>
>
>
> --
> WBR
> Maxim aka solomax
>

Re: Method chaining

Posted by Maxim Solodovnik <so...@gmail.com>.
I personally like chaining in Wicket


On Fri, Jan 31, 2014 at 9:08 PM, Martin Grigorov <mg...@apache.org>wrote:

> Hi,
>
> What others think about https://issues.apache.org/jira/browse/WICKET-5459?
> Should Wicket use "return this" pattern where makes sense instead of 'void'
> return type ?
>
> One problem that I see is with:
> MyPage.doSomething() will/may return some base type of MyPage.
> I remember some trink for Java to make this simpler but AFAIR it involved
> some longer generics signature for the class that use it.
>
>
>
> Martin Grigorov
> Wicket Training and Consulting
>



-- 
WBR
Maxim aka solomax