I see two kinds of accessor patterns in the wild:

   1. `int getX()` and `setX(int x)` on mutable objects
   2. `int x()` and `withX(int x)` on immutable objects

With records, Java gravitates towards `int x()` and `with { x = x' }`, aka.
withers
<https://github.com/openjdk/amber-docs/blob/master/eg-drafts/reconstruction-records-and-classes.md>.
Scala and Kotlin ecosystems sort of embrace the very same via named
arguments and/or copy methods.

In `release-2.x`, we follow the 1st accessor pattern; whereas in `master`,
we follow both. :facepalm:

I suggest sticking to the 1st approach, everywhere, since

   1. We only have mutable objects
   2. >90% of the project already sticks to the 1st approach
   3. Java ecosystem is dominated by the 1st approach
   4. No backward compatibility issues
   5. No merge conflicts while syncing branches

Maybe we can re-open this subject in the `release-3.x` branch far in the
future.

I have created #1206 <https://github.com/apache/logging-log4j2/issues/1206>
to address this. Feel free to submit a PR.

On Sun, 8 Jan 2023, 22:49 Matt Sicker <m...@musigma.org> wrote:

> In my experience, I’ve usually used withFoo() methods for making immutable
> copies of things while I’ve used setFoo() methods for builder classes as
> those are mutable. In Log4j, we have a mix of these two patterns. I’d like
> us to be more consistent with this.
>
> Which style should we use in Log4j?
> —
> Matt Sicker
>
>

Reply via email to