You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2016/11/14 19:55:48 UTC

Builder pattern

I recently added a bunch of Builders in various places and used "with" as
the setter method prefix.

We have a mix of "set" and "with" in our Builders ATM.

I am thinking of going back and changing the builders I added since 2.7
from "with" to "set".

I am liking "set" better because:
- More standard than "with"
- Therefore IDEs like Eclipse, by default will not generate warnings for
setter methods when the param name is the same as the ivar (the param name
is hidding a field)
- Easier to remember to type "s" for "set" when using code completion
- shorter than "set"

I still like "with" ONLY in the case when a NEW object is generated, which
is usually not (never?) the case in our Builders.

Any thoughts?

Gary

-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Builder pattern

Posted by Matt Sicker <bo...@gmail.com>.
I'd support deprecating the with methods and making set methods the
canonical one.

As for is versus get, is it because some of them return Boolean rather than
boolean? I generally prefer the is prefix for boolean and avoid using
Boolean whenever possible.

On 14 November 2016 at 17:37, Gary Gregory <ga...@gmail.com> wrote:

> I marked existing methods @Deprecated. I did not delete anything in order
> to avoid breaking BC as much as possible.
>
> I'd like to change the existing Builders that use "with" to "set". This
> would not break config files but it would break code. Is it over the top to
> deprecate the "with" methods and add "set" methods?
>
> I like consistency :-)
>
> I am also wondering about boolean accessors. We have some "is" and some
> "get" accessors for booleans...
>
> Gary
>
> On Mon, Nov 14, 2016 at 3:26 PM, Remko Popma <re...@gmail.com>
> wrote:
>
>> Are Builders used by users for custom plugins?
>> Should we deprecate and keep the old methods around for a while to avoid
>> breaking user code?
>>
>> Remko
>>
>> Sent from my iPhone
>>
>> On 15 Nov 2016, at 5:22, Matt Sicker <bo...@gmail.com> wrote:
>>
>> I like using set instead of with for builders. I've only been using with
>> methods lately for constructing modified copies of the current object which
>> doesn't exactly fit the builder idea (since the builder is modified and not
>> copied). I've also used builders without any prefix, but that would look
>> rather silly mixed with setters and withers at this point.
>>
>> On 14 November 2016 at 13:55, Gary Gregory <ga...@gmail.com>
>> wrote:
>>
>>> I recently added a bunch of Builders in various places and used "with"
>>> as the setter method prefix.
>>>
>>> We have a mix of "set" and "with" in our Builders ATM.
>>>
>>> I am thinking of going back and changing the builders I added since 2.7
>>> from "with" to "set".
>>>
>>> I am liking "set" better because:
>>> - More standard than "with"
>>> - Therefore IDEs like Eclipse, by default will not generate warnings for
>>> setter methods when the param name is the same as the ivar (the param name
>>> is hidding a field)
>>> - Easier to remember to type "s" for "set" when using code completion
>>> - shorter than "set"
>>>
>>> I still like "with" ONLY in the case when a NEW object is generated,
>>> which is usually not (never?) the case in our Builders.
>>>
>>> Any thoughts?
>>>
>>> Gary
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>>
>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
>>> JUnit in Action, Second Edition
>>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>>>
>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
>>> Spring Batch in Action
>>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>

Re: Builder pattern

Posted by Gary Gregory <ga...@gmail.com>.
I marked existing methods @Deprecated. I did not delete anything in order
to avoid breaking BC as much as possible.

I'd like to change the existing Builders that use "with" to "set". This
would not break config files but it would break code. Is it over the top to
deprecate the "with" methods and add "set" methods?

I like consistency :-)

I am also wondering about boolean accessors. We have some "is" and some
"get" accessors for booleans...

Gary

On Mon, Nov 14, 2016 at 3:26 PM, Remko Popma <re...@gmail.com> wrote:

> Are Builders used by users for custom plugins?
> Should we deprecate and keep the old methods around for a while to avoid
> breaking user code?
>
> Remko
>
> Sent from my iPhone
>
> On 15 Nov 2016, at 5:22, Matt Sicker <bo...@gmail.com> wrote:
>
> I like using set instead of with for builders. I've only been using with
> methods lately for constructing modified copies of the current object which
> doesn't exactly fit the builder idea (since the builder is modified and not
> copied). I've also used builders without any prefix, but that would look
> rather silly mixed with setters and withers at this point.
>
> On 14 November 2016 at 13:55, Gary Gregory <ga...@gmail.com> wrote:
>
>> I recently added a bunch of Builders in various places and used "with" as
>> the setter method prefix.
>>
>> We have a mix of "set" and "with" in our Builders ATM.
>>
>> I am thinking of going back and changing the builders I added since 2.7
>> from "with" to "set".
>>
>> I am liking "set" better because:
>> - More standard than "with"
>> - Therefore IDEs like Eclipse, by default will not generate warnings for
>> setter methods when the param name is the same as the ivar (the param name
>> is hidding a field)
>> - Easier to remember to type "s" for "set" when using code completion
>> - shorter than "set"
>>
>> I still like "with" ONLY in the case when a NEW object is generated,
>> which is usually not (never?) the case in our Builders.
>>
>> Any thoughts?
>>
>> Gary
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
>> JUnit in Action, Second Edition
>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
>> Spring Batch in Action
>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Builder pattern

Posted by Remko Popma <re...@gmail.com>.
Of course only for the Builders that were published as of 2.7. The Builders we're adding in 2.8 can just use set. 

Sent from my iPhone

> On 15 Nov 2016, at 8:26, Remko Popma <re...@gmail.com> wrote:
> 
> Are Builders used by users for custom plugins?
> Should we deprecate and keep the old methods around for a while to avoid breaking user code?
> 
> Remko
> 
> Sent from my iPhone
> 
>> On 15 Nov 2016, at 5:22, Matt Sicker <bo...@gmail.com> wrote:
>> 
>> I like using set instead of with for builders. I've only been using with methods lately for constructing modified copies of the current object which doesn't exactly fit the builder idea (since the builder is modified and not copied). I've also used builders without any prefix, but that would look rather silly mixed with setters and withers at this point.
>> 
>>> On 14 November 2016 at 13:55, Gary Gregory <ga...@gmail.com> wrote:
>>> I recently added a bunch of Builders in various places and used "with" as the setter method prefix.
>>> 
>>> We have a mix of "set" and "with" in our Builders ATM.
>>> 
>>> I am thinking of going back and changing the builders I added since 2.7 from "with" to "set".
>>> 
>>> I am liking "set" better because:
>>> - More standard than "with"
>>> - Therefore IDEs like Eclipse, by default will not generate warnings for setter methods when the param name is the same as the ivar (the param name is hidding a field)
>>> - Easier to remember to type "s" for "set" when using code completion
>>> - shorter than "set"
>>> 
>>> I still like "with" ONLY in the case when a NEW object is generated, which is usually not (never?) the case in our Builders.
>>> 
>>> Any thoughts?
>>> 
>>> Gary
>>> 
>>> -- 
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>> Java Persistence with Hibernate, Second Edition 
>>> JUnit in Action, Second Edition 
>>> Spring Batch in Action 
>>> Blog: http://garygregory.wordpress.com 
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>> 
>> 
>> 
>> -- 
>> Matt Sicker <bo...@gmail.com>

Re: Builder pattern

Posted by Remko Popma <re...@gmail.com>.
Are Builders used by users for custom plugins?
Should we deprecate and keep the old methods around for a while to avoid breaking user code?

Remko

Sent from my iPhone

> On 15 Nov 2016, at 5:22, Matt Sicker <bo...@gmail.com> wrote:
> 
> I like using set instead of with for builders. I've only been using with methods lately for constructing modified copies of the current object which doesn't exactly fit the builder idea (since the builder is modified and not copied). I've also used builders without any prefix, but that would look rather silly mixed with setters and withers at this point.
> 
>> On 14 November 2016 at 13:55, Gary Gregory <ga...@gmail.com> wrote:
>> I recently added a bunch of Builders in various places and used "with" as the setter method prefix.
>> 
>> We have a mix of "set" and "with" in our Builders ATM.
>> 
>> I am thinking of going back and changing the builders I added since 2.7 from "with" to "set".
>> 
>> I am liking "set" better because:
>> - More standard than "with"
>> - Therefore IDEs like Eclipse, by default will not generate warnings for setter methods when the param name is the same as the ivar (the param name is hidding a field)
>> - Easier to remember to type "s" for "set" when using code completion
>> - shorter than "set"
>> 
>> I still like "with" ONLY in the case when a NEW object is generated, which is usually not (never?) the case in our Builders.
>> 
>> Any thoughts?
>> 
>> Gary
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>> Java Persistence with Hibernate, Second Edition 
>> JUnit in Action, Second Edition 
>> Spring Batch in Action 
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>

Re: Builder pattern

Posted by Matt Sicker <bo...@gmail.com>.
I like using set instead of with for builders. I've only been using with
methods lately for constructing modified copies of the current object which
doesn't exactly fit the builder idea (since the builder is modified and not
copied). I've also used builders without any prefix, but that would look
rather silly mixed with setters and withers at this point.

On 14 November 2016 at 13:55, Gary Gregory <ga...@gmail.com> wrote:

> I recently added a bunch of Builders in various places and used "with" as
> the setter method prefix.
>
> We have a mix of "set" and "with" in our Builders ATM.
>
> I am thinking of going back and changing the builders I added since 2.7
> from "with" to "set".
>
> I am liking "set" better because:
> - More standard than "with"
> - Therefore IDEs like Eclipse, by default will not generate warnings for
> setter methods when the param name is the same as the ivar (the param name
> is hidding a field)
> - Easier to remember to type "s" for "set" when using code completion
> - shorter than "set"
>
> I still like "with" ONLY in the case when a NEW object is generated, which
> is usually not (never?) the case in our Builders.
>
> Any thoughts?
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>