Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Builder/SuperBuilder setterPrefix configurable from lombok.config #3159

Closed
mickroll opened this issue Mar 31, 2022 · 2 comments
Closed

Comments

@mickroll
Copy link

As there is the @Builder(setterPrefix = "...") option, it would make sense to have the ability of setting it once across the project at the lombok.config.
An example would be using lombok.builder.setterPrefix = set to have a project-wide prefix set for bean-like builder access.
For consistency, the config value should be used as default value by @SuperBuilder as well, just like lombok.builder.className is used by @SuperBuilder already.

Justification:

  • Improved signal-to-noise ratio
  • Better readability (arguably)
  • Helps keeping project convention consistent

BTW this feature request somewhat follows #2849, to have a project wide consistent config for (very) often used lombok features.

@rzwitserloot
Copy link
Collaborator

We won't do this. The reason we offered it in the first place is if you're making a builder that needs to fit specific needs, e.g. because it has to implement an interface or you're using it with some backwards library that expects silly defaults.

Specifically, with (the common prefix) is, in our opinion, highly misleading. There's no point in having a lombok.config setting other than 'I want to apply it everywhere regardless of circumstance' and we're not (currently) seeing the point of that. Builder is in its infancy, relatively speaking. 'there are many ways to do it' engenders pointless style quibbles and needlessly increases learning curves.

We like the java community and wouldn't want to make it worse by introducing pointless customization options like that.

@topr
Copy link

topr commented May 24, 2024

@rzwitserloot this would be very helpful though. The overarching idea behind Lombok is to reduce boilerplate and noise in code, isn't it?

So now needing to add a specific param by in each every @Builder is counter-effective to achieving that goal and also makes it much tougher to keep a codebase consistent.

I appreciate your great input into java community but your position in which you think you know better what application, code style, or any other issue anyone may face or need is not very considerate, is it?

Here's an use case in which Lombok's default builder name convention doesn't work very well.

Prod code in Java

@Builder
record Something(@NonNull NonBlankString foo, @NonNull NonNegativeInteger bar) {}

Test fixture DSL in Groovy

class SomethingDsl {
    @Delegate
    private final SomethingBuilder builder = Something.builder()

    static Something anySomething(@DelegatesTo(SomethingDsl) Closure overrides = {}) {
        new SomethingDsl().with {
            foo 'foo-1'
            bar 3
            with overrides
            build()
    }
    
    // convenience setters to improve SNR further on the use side

    void foo(String value) {
        foo new NonBlankString(value)
    }

    void bar(Integer value) {
        bar new NonNegativeInteger(value)
    }
}

Test code in Spock

given:
def foo = 'the-foo'

when:
def something = anySomething { // statically imported from SomethingDsl
    foo foo // here is the problem where the name of local variable clashes with the default setter name so this doesn't work
}

then:
// whatever the assertion

If the DSL's underlying builder had any setter prefix, the clash wouldn't happen, i.e.

given:
def foo = 'the-foo'

when:
def something = anySomething { // statically imported from SomethingDsl
    withFoo foo // here is the problem where the name of local variable clashes with the default setter name so this doesn't work
}

then:
// whatever the assertion

I've been now going through multiple in our organization (some quite large) for a couple of years to ensure that explicit setterPrefix is on each and every @Builder so that it matches project/organization convention, and also chasing other devs about it. But it's tedious and like whack-em-all 😔

A global configuration option would really save a lot of otherwise unnecessarily wasted time, effort and noise in code 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants