You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martijn Dashorst <ma...@gmail.com> on 2009/11/15 18:39:44 UTC

Cutting down on the repetitive type identifiers for generics

I hate repeating myself and being the compiler's teacher. IMHO the
generics that are implemented in Java resulted in terrible code where
you have to repeat yourself over and over and over. Are you sure your
text field holds a String and your model returns a String?

TextField<String> field = new TextField<String>("someId", new
PropertyModel<String>(foo, "property"));

This counts for 3 times the type String. In a recent discussion with
Igor on ##wicket, we saw a way to remove at least 1 String. By
providing model factory methods for concrete models: Model,
CompoundPropertyModel and PropertyModel. For abstract models it
doesn't make sense...

Igor suggested the following syntax:

TextField<String> field = new TextField<String>("someId",
PropertyModel.of(foo, "property"));

i.e. ModelType.of(....)

I am +1 for adding these methods.

We can do the same for components, although the benefit is typically
less, and it might even send our users down the wrong path thinking
they can't use the 'new' keyword.

TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
"property"));

WDYT?

Martijn
-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.4 increases type safety for web applications
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0

Re: Cutting down on the repetitive type identifiers for generics

Posted by Pedro Santos <pe...@gmail.com>.
I know it is an minor thing, but the creation act that the new keyword
exposes, the 'of' method don't has. IMO the simple fact of an method name
does not contain an verb is an anti-pattern.

On Tue, Nov 17, 2009 at 2:50 PM, nino martinez wael <
nino.martinez.wael@gmail.com> wrote:

> im +1, unless Jeremy can tell why he believes it will hit a anti patter..
>
> 2009/11/16 Jeremy Thomerson <je...@wickettraining.com>
>
> > On Sun, Nov 15, 2009 at 11:39 AM, Martijn Dashorst <
> > martijn.dashorst@gmail.com> wrote:
> >
> > > i.e. ModelType.of(....)
> > >
> > > I am +1 for adding these methods.
> > >
> >
> > I'm +1 for the model-type methods, although there are so many models that
> > are not final classes that it really won't save tons of code.  Mainly in
> > the
> > *PropertyModel family.
> >
> >
> > > We can do the same for components, although the benefit is typically
> > > less, and it might even send our users down the wrong path thinking
> > > they can't use the 'new' keyword.
> > >
> > > TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
> > > "property"));
> > >
> >
> > I'm -1 on doing it for components.  I think it will lead to an
> > anti-pattern.
> >
> > --
> > Jeremy Thomerson
> > http://www.wickettraining.com
> >
>



-- 
Pedro Henrique Oliveira dos Santos

Re: Cutting down on the repetitive type identifiers for generics

Posted by nino martinez wael <ni...@gmail.com>.
Argh, that is horrible. :(


2009/11/17 Igor Vaynberg <ig...@gmail.com>

> not to mention that some components have 6 constructors, and that
> means having 6 of methods :|
>
> -igor
>
> On Tue, Nov 17, 2009 at 9:33 AM, Jeremy Thomerson
> <je...@wickettraining.com> wrote:
> > Because we'll get questions to the list like:
> >
> > How can I create my own component since I have to instantiate them using
> > Label.of("foo", PropertyModel.of(bar, "foo"))?  How can I override that?
>  Do
> > I have to override the static method "of"?
> >
> > Sadly, I think that's what it will cause.
> >
> > --
> > Jeremy Thomerson
> > http://www.wickettraining.com
> >
> >
> >
> > On Tue, Nov 17, 2009 at 10:50 AM, nino martinez wael <
> > nino.martinez.wael@gmail.com> wrote:
> >
> >> im +1, unless Jeremy can tell why he believes it will hit a anti
> patter..
> >>
> >> 2009/11/16 Jeremy Thomerson <je...@wickettraining.com>
> >>
> >> > On Sun, Nov 15, 2009 at 11:39 AM, Martijn Dashorst <
> >> > martijn.dashorst@gmail.com> wrote:
> >> >
> >> > > i.e. ModelType.of(....)
> >> > >
> >> > > I am +1 for adding these methods.
> >> > >
> >> >
> >> > I'm +1 for the model-type methods, although there are so many models
> that
> >> > are not final classes that it really won't save tons of code.  Mainly
> in
> >> > the
> >> > *PropertyModel family.
> >> >
> >> >
> >> > > We can do the same for components, although the benefit is typically
> >> > > less, and it might even send our users down the wrong path thinking
> >> > > they can't use the 'new' keyword.
> >> > >
> >> > > TextField<String> field = TextField.of("someId",
> PropertyModel.of(foo,
> >> > > "property"));
> >> > >
> >> >
> >> > I'm -1 on doing it for components.  I think it will lead to an
> >> > anti-pattern.
> >> >
> >> > --
> >> > Jeremy Thomerson
> >> > http://www.wickettraining.com
> >> >
> >>
> >
>

Re: Cutting down on the repetitive type identifiers for generics

Posted by Igor Vaynberg <ig...@gmail.com>.
not to mention that some components have 6 constructors, and that
means having 6 of methods :|

-igor

On Tue, Nov 17, 2009 at 9:33 AM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> Because we'll get questions to the list like:
>
> How can I create my own component since I have to instantiate them using
> Label.of("foo", PropertyModel.of(bar, "foo"))?  How can I override that?  Do
> I have to override the static method "of"?
>
> Sadly, I think that's what it will cause.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
>
> On Tue, Nov 17, 2009 at 10:50 AM, nino martinez wael <
> nino.martinez.wael@gmail.com> wrote:
>
>> im +1, unless Jeremy can tell why he believes it will hit a anti patter..
>>
>> 2009/11/16 Jeremy Thomerson <je...@wickettraining.com>
>>
>> > On Sun, Nov 15, 2009 at 11:39 AM, Martijn Dashorst <
>> > martijn.dashorst@gmail.com> wrote:
>> >
>> > > i.e. ModelType.of(....)
>> > >
>> > > I am +1 for adding these methods.
>> > >
>> >
>> > I'm +1 for the model-type methods, although there are so many models that
>> > are not final classes that it really won't save tons of code.  Mainly in
>> > the
>> > *PropertyModel family.
>> >
>> >
>> > > We can do the same for components, although the benefit is typically
>> > > less, and it might even send our users down the wrong path thinking
>> > > they can't use the 'new' keyword.
>> > >
>> > > TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
>> > > "property"));
>> > >
>> >
>> > I'm -1 on doing it for components.  I think it will lead to an
>> > anti-pattern.
>> >
>> > --
>> > Jeremy Thomerson
>> > http://www.wickettraining.com
>> >
>>
>

Re: Cutting down on the repetitive type identifiers for generics

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Because we'll get questions to the list like:

How can I create my own component since I have to instantiate them using
Label.of("foo", PropertyModel.of(bar, "foo"))?  How can I override that?  Do
I have to override the static method "of"?

Sadly, I think that's what it will cause.

--
Jeremy Thomerson
http://www.wickettraining.com



On Tue, Nov 17, 2009 at 10:50 AM, nino martinez wael <
nino.martinez.wael@gmail.com> wrote:

> im +1, unless Jeremy can tell why he believes it will hit a anti patter..
>
> 2009/11/16 Jeremy Thomerson <je...@wickettraining.com>
>
> > On Sun, Nov 15, 2009 at 11:39 AM, Martijn Dashorst <
> > martijn.dashorst@gmail.com> wrote:
> >
> > > i.e. ModelType.of(....)
> > >
> > > I am +1 for adding these methods.
> > >
> >
> > I'm +1 for the model-type methods, although there are so many models that
> > are not final classes that it really won't save tons of code.  Mainly in
> > the
> > *PropertyModel family.
> >
> >
> > > We can do the same for components, although the benefit is typically
> > > less, and it might even send our users down the wrong path thinking
> > > they can't use the 'new' keyword.
> > >
> > > TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
> > > "property"));
> > >
> >
> > I'm -1 on doing it for components.  I think it will lead to an
> > anti-pattern.
> >
> > --
> > Jeremy Thomerson
> > http://www.wickettraining.com
> >
>

Re: Cutting down on the repetitive type identifiers for generics

Posted by nino martinez wael <ni...@gmail.com>.
im +1, unless Jeremy can tell why he believes it will hit a anti patter..

2009/11/16 Jeremy Thomerson <je...@wickettraining.com>

> On Sun, Nov 15, 2009 at 11:39 AM, Martijn Dashorst <
> martijn.dashorst@gmail.com> wrote:
>
> > i.e. ModelType.of(....)
> >
> > I am +1 for adding these methods.
> >
>
> I'm +1 for the model-type methods, although there are so many models that
> are not final classes that it really won't save tons of code.  Mainly in
> the
> *PropertyModel family.
>
>
> > We can do the same for components, although the benefit is typically
> > less, and it might even send our users down the wrong path thinking
> > they can't use the 'new' keyword.
> >
> > TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
> > "property"));
> >
>
> I'm -1 on doing it for components.  I think it will lead to an
> anti-pattern.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>

Re: Cutting down on the repetitive type identifiers for generics

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Sun, Nov 15, 2009 at 11:39 AM, Martijn Dashorst <
martijn.dashorst@gmail.com> wrote:

> i.e. ModelType.of(....)
>
> I am +1 for adding these methods.
>

I'm +1 for the model-type methods, although there are so many models that
are not final classes that it really won't save tons of code.  Mainly in the
*PropertyModel family.


> We can do the same for components, although the benefit is typically
> less, and it might even send our users down the wrong path thinking
> they can't use the 'new' keyword.
>
> TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
> "property"));
>

I'm -1 on doing it for components.  I think it will lead to an
anti-pattern.

--
Jeremy Thomerson
http://www.wickettraining.com

Re: Cutting down on the repetitive type identifiers for generics

Posted by Igor Vaynberg <ig...@gmail.com>.
PropertyModel.of(x,y) is what we use in Model

-igor

On Thu, Dec 3, 2009 at 3:11 AM, Johan Compagner <jc...@gmail.com> wrote:
> the bad news is that it seems it is delayed again until the end of 2010??
>
>
> back on the static methods, PropertyModel.getInstance(x,y) is a bit to long
> i guess and PropertyModel.get(x.y)  is also not not sounding quite right.
>
>
>
> On Thu, Dec 3, 2009 at 11:42, Vladimir K <ko...@gmail.com> wrote:
>
>>
>> Martijn,
>>
>> I hope a new feature called "type inference" coming in JDK7 could help java
>> devs to omit repetitive typing of generic parameters.
>>
>> And another good news - JDK 7 will do provide closures.
>>
>>
>> Martijn Dashorst wrote:
>> >
>> > I hate repeating myself and being the compiler's teacher. IMHO the
>> > generics that are implemented in Java resulted in terrible code where
>> > you have to repeat yourself over and over and over. Are you sure your
>> > text field holds a String and your model returns a String?
>> >
>> > TextField<String> field = new TextField<String>("someId", new
>> > PropertyModel<String>(foo, "property"));
>> >
>> > This counts for 3 times the type String. In a recent discussion with
>> > Igor on ##wicket, we saw a way to remove at least 1 String. By
>> > providing model factory methods for concrete models: Model,
>> > CompoundPropertyModel and PropertyModel. For abstract models it
>> > doesn't make sense...
>> >
>> > Igor suggested the following syntax:
>> >
>> > TextField<String> field = new TextField<String>("someId",
>> > PropertyModel.of(foo, "property"));
>> >
>> > i.e. ModelType.of(....)
>> >
>> > I am +1 for adding these methods.
>> >
>> > We can do the same for components, although the benefit is typically
>> > less, and it might even send our users down the wrong path thinking
>> > they can't use the 'new' keyword.
>> >
>> > TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
>> > "property"));
>> >
>> > WDYT?
>> >
>> > Martijn
>> > --
>> > Become a Wicket expert, learn from the best: http://wicketinaction.com
>> > Apache Wicket 1.4 increases type safety for web applications
>> > Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Cutting-down-on-the-repetitive-type-identifiers-for-generics-tp26361334p26623904.html
>> Sent from the Wicket - Dev mailing list archive at Nabble.com.
>>
>>
>

Re: Cutting down on the repetitive type identifiers for generics

Posted by Johan Compagner <jc...@gmail.com>.
the bad news is that it seems it is delayed again until the end of 2010??


back on the static methods, PropertyModel.getInstance(x,y) is a bit to long
i guess and PropertyModel.get(x.y)  is also not not sounding quite right.



On Thu, Dec 3, 2009 at 11:42, Vladimir K <ko...@gmail.com> wrote:

>
> Martijn,
>
> I hope a new feature called "type inference" coming in JDK7 could help java
> devs to omit repetitive typing of generic parameters.
>
> And another good news - JDK 7 will do provide closures.
>
>
> Martijn Dashorst wrote:
> >
> > I hate repeating myself and being the compiler's teacher. IMHO the
> > generics that are implemented in Java resulted in terrible code where
> > you have to repeat yourself over and over and over. Are you sure your
> > text field holds a String and your model returns a String?
> >
> > TextField<String> field = new TextField<String>("someId", new
> > PropertyModel<String>(foo, "property"));
> >
> > This counts for 3 times the type String. In a recent discussion with
> > Igor on ##wicket, we saw a way to remove at least 1 String. By
> > providing model factory methods for concrete models: Model,
> > CompoundPropertyModel and PropertyModel. For abstract models it
> > doesn't make sense...
> >
> > Igor suggested the following syntax:
> >
> > TextField<String> field = new TextField<String>("someId",
> > PropertyModel.of(foo, "property"));
> >
> > i.e. ModelType.of(....)
> >
> > I am +1 for adding these methods.
> >
> > We can do the same for components, although the benefit is typically
> > less, and it might even send our users down the wrong path thinking
> > they can't use the 'new' keyword.
> >
> > TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
> > "property"));
> >
> > WDYT?
> >
> > Martijn
> > --
> > Become a Wicket expert, learn from the best: http://wicketinaction.com
> > Apache Wicket 1.4 increases type safety for web applications
> > Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Cutting-down-on-the-repetitive-type-identifiers-for-generics-tp26361334p26623904.html
> Sent from the Wicket - Dev mailing list archive at Nabble.com.
>
>

Re: Cutting down on the repetitive type identifiers for generics

Posted by Vladimir K <ko...@gmail.com>.
Martijn,

I hope a new feature called "type inference" coming in JDK7 could help java
devs to omit repetitive typing of generic parameters.

And another good news - JDK 7 will do provide closures.


Martijn Dashorst wrote:
> 
> I hate repeating myself and being the compiler's teacher. IMHO the
> generics that are implemented in Java resulted in terrible code where
> you have to repeat yourself over and over and over. Are you sure your
> text field holds a String and your model returns a String?
> 
> TextField<String> field = new TextField<String>("someId", new
> PropertyModel<String>(foo, "property"));
> 
> This counts for 3 times the type String. In a recent discussion with
> Igor on ##wicket, we saw a way to remove at least 1 String. By
> providing model factory methods for concrete models: Model,
> CompoundPropertyModel and PropertyModel. For abstract models it
> doesn't make sense...
> 
> Igor suggested the following syntax:
> 
> TextField<String> field = new TextField<String>("someId",
> PropertyModel.of(foo, "property"));
> 
> i.e. ModelType.of(....)
> 
> I am +1 for adding these methods.
> 
> We can do the same for components, although the benefit is typically
> less, and it might even send our users down the wrong path thinking
> they can't use the 'new' keyword.
> 
> TextField<String> field = TextField.of("someId", PropertyModel.of(foo,
> "property"));
> 
> WDYT?
> 
> Martijn
> -- 
> Become a Wicket expert, learn from the best: http://wicketinaction.com
> Apache Wicket 1.4 increases type safety for web applications
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0
> 
> 

-- 
View this message in context: http://old.nabble.com/Cutting-down-on-the-repetitive-type-identifiers-for-generics-tp26361334p26623904.html
Sent from the Wicket - Dev mailing list archive at Nabble.com.