Skip to content

Breaking change - renaming old mutable setXX methods #191

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bbakerman
Copy link
Member

#190

We changed the semantics of DataLoaderOption to be immutable but we didnt change the API signature and this led to confusion and the possibility of bugs where previously mutable calls not longer took effect

See the issue from more details

This now makes this a breaking change and will fail at compile time

@bbakerman bbakerman added this to the 5.0.0 milestone May 1, 2025
@@ -196,7 +196,7 @@ public boolean cachingEnabled() {
* @param cachingEnabled {@code true} to enable caching, {@code false} otherwise
* @return a new data loader options instance for fluent coding
*/
public DataLoaderOptions setCachingEnabled(boolean cachingEnabled) {
public DataLoaderOptions withCachingEnabled(boolean cachingEnabled) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about making these static to discourage chaining and removing the newOptions function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by static. But while agree we should have made a compiler breaking change the first time (which we are now) I do still want to retain immutable options chaining.

Copy link

@zsmoore zsmoore May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chaining is good however even with this change you can still write

DataLoaderOptions options = DataLoaderOptions.newOptions()
                .withMaxBatchSize(5);
        
        options.withBatchingEnabled(false);

Which is breaking

I feel like instead if you remove newOptions() and swap to static the IDE will hint the bad pattern of static methods on the instance, no longer recommend chaining on the concrete instance and hint people towards chaining only on the builder

Screenshot 2025-05-01 at 9 39 25 AM IDE hinting to not use the static methods on the instance which would break the behavior Screenshot 2025-05-01 at 9 48 11 AM

IDE not suggesting chaining of the static methods

Screenshot 2025-05-01 at 9 51 52 AM

(It will allow you to explicitly type it out but won't suggest it and will warn if you do) This code is technically valid but i feel like we want to push people to the Builder since it exists now

Screenshot 2025-05-01 at 9 41 49 AM

Push people towards proper builder pattern

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I dont mind options.setX(x).setY(y) but since we stuff up the API during the immutability change then we have created a muddy water situation

So you are right, we need to be more clear in this case because of the previous history

So I have deleted all the with method and now only have the builder. So every one has to move to a new place which is more sympathetic to immutability

Thanks for the feedback.

this.valueCacheOptions = other.valueCacheOptions;
this.batchLoaderScheduler = other.batchLoaderScheduler;
this.instrumentation = other.instrumentation;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no point any longer and anyway lets use builders with this breaking change

*/
public DataLoaderOptions setBatchingEnabled(boolean batchingEnabled) {
return builder().setBatchingEnabled(batchingEnabled).build();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the object -> mutate -> new object methods are removed and now only in the builder

*
* @param batchingEnabled {@code true} to enable batch loading, {@code false} otherwise
* @return this builder for fluent coding
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doco all transferred from above set methods

Copy link

@zsmoore zsmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code changes lgtm ty!

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

Successfully merging this pull request may close these issues.

2 participants