Gary, I also prefer "set" but I didn't want to pollute my objectivity in explaining the options. My cards are now laid down. :-) BTW, "with" has been used in JSR-310 (Java 8 Date/Time) for immutable objects "mutability"; that prefix means you get back a new object when "changing" the property (think String behavior). That doesn't apply here so I recommend avoiding "with" too.
Cheers, Paul On Mon, Nov 30, 2015 at 2:13 PM, Gary Gregory <garydgreg...@gmail.com> wrote: > I find using foo() instead of setFoo() somewhat confusing. It forces you > to think that you are using a builder and you cannot just do > set/auto-complete. In addition, when foo is a verb, it's misleading, since > the call does not perform anything but merely sets a value. > > Gary > > On Mon, Nov 30, 2015 at 11:49 AM, Paul Benedict <pbened...@apache.org> > wrote: > >> I actually had an interesting discussion lately with builders; so this >> topic interests me. Since builders are inherently mutable (and they should >> be right? it's a process of constructing an object), it's okay to use "set" >> methods. For example, see Spring's BeanDefinitionBuilder [1]. But you don't >> have to take this approach. It's also fine to name the mutator like an >> operation; see Java EE's URIBuilder [2] for that approach. >> >> My preference comes down to whether the in-process information is >> retrievable? If so, I prefer getter/setter; otherwise just go with foo() >> over setFoo() >> >> [1] >> https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/support/BeanDefinitionBuilder.html >> [2] https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriBuilder.html >> >> Cheers, >> Paul >> >> On Mon, Nov 30, 2015 at 1:44 PM, Gary Gregory <garydgreg...@gmail.com> >> wrote: >> >>> I like "set" better, but that's just because I like to type "set" and >>> use auto-complete. I'd rather not have to decide if I have to type "set" or >>> "with" and then auto-complete. >>> >>> Gary >>> >>> On Mon, Nov 30, 2015 at 11:36 AM, Matt Sicker <boa...@gmail.com> wrote: >>> >>>> Sorry, but I introduced this problem a while ago by using withFoo() in >>>> some builder classes, but setFoo() in other builder classes. Both are >>>> equally valid naming schemes for builder classes. It would be great to be >>>> consistent, though. Which one would be preferable? >>>> >>>> -- >>>> Matt Sicker <boa...@gmail.com> >>>> >>> >>> >>> >>> -- >>> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org >>> Java Persistence with Hibernate, Second Edition >>> <http://www.manning.com/bauer3/> >>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> >>> Spring Batch in Action <http://www.manning.com/templier/> >>> Blog: http://garygregory.wordpress.com >>> Home: http://garygregory.com/ >>> Tweet! http://twitter.com/GaryGregory >>> >> >> > > > -- > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org > Java Persistence with Hibernate, Second Edition > <http://www.manning.com/bauer3/> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > Spring Batch in Action <http://www.manning.com/templier/> > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory >