-
Notifications
You must be signed in to change notification settings - Fork 321
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
Reduce usage of Guava #2975
Comments
In Java-19 there is even static factory method HashMap.newHashMap(int) that can be used as a drop-in replacement once Java-19 or later is required. Part of eclipse-xtext#2975
In Java-19 there is even static factory method HashMap.newHashMap(int) that can be used as a drop-in replacement once Java-19 or later is required. For now I calculate the necessary capacity explicitly using the formula: expected-size *4/3+1 Part of eclipse-xtext#2975
Before putting more effort into this, let's analyze the impact of such a change and agree it's worthwhile to pursue. Can we agree on a few things:
What is the net-effect of overloading existing APIs with java.util.function types where currently Guava's pseudo-deprecated types are used? Likely warnings in source code. Is it any better for an existing code-base? I've doubts. Before we follow through and look at the detailled implications of whatever change we're going to make, I'd like to understand why it is better. Better beyond an academic perception of better. I want to see that the disruption is carrying its own weight. Of course this is only my opinion, so others are clearly invited to share their thoughts, too. But before more time is (maybe wasted, maybe not) on code changes, let's agree on a goal and let's make a plan that'll lead to that goal. |
In general, I'd have no problem replacing things like I have doubts (see #2978 (comment)) that having overloaded methods with functional interfaces would work: the Java compiler would issue an error if you pass a lambda expression, wouldn't it? If switching to Java functional interfaces instead of the Guava ones is considered, I think it would be better to simply replace the functional interfaces from Guava with the ones of Java without deprecation and overloading. That would be API breakage, but it should go completely unnoticed if clients used to call such methods with lambda expressions. I don't know if it could give problems from a binary point of view, though. |
That would indeed be source-compatible but not binary-compatible. |
In order to resolve the issue that the compiler often picks the 'wrong' deprecated overload another alternative would be to slightly change the name of the method as mentioned in #2978 (comment). IIRC JDT now even offers a quick-fix to use the replacement (if only one method is mentioned in the
Sebastian is right, that would be binary incompatible because the name all arguments and the return type of the method selected by the compiler is written into the byte-code. Because even the return-type is persisted you cannot even narrow the return type of a method without breaking binary-compatibility although it would be fully source-compatible and you cannot have methods in java that are only different by their return type: https://stackoverflow.com/a/58272625/14542697
In general I agree with that, but with the restriction that I don't think that binary compatibility has to be retained forever by all means. Even Java itself breaks sometimes by removing functionality (the latest example is the degradation of
Yes. But I would say that the consequences depend on who exactly the users are and what is considered a benefit. In my opinion a benefit for the user is also if the developer's live is made easier so that they can spend more time on other beneficial things or can even continue development at all. And about the users, there are users of xtext that generate new languages and users of that generated languages.
It is and I would say it was so successful that many parts made it in the JDK, which often allows to remove it. There are still many useful things in it and as initially written I cannot even tell if it is currently reasonably possible to replace all its usage in Xtext. But starting with trivial things would make it easier to get a complete overview. And if it would not yet be possible to complete this, it would be easier whenever it is possible in the future.
Yes. And alone removing the re-exports would probably already help a lot to ease the maintenance. And I think there are promising ways to 'deprecate' that using fragments as mentioned in #2668 (comment). For more background why the current situation can be problematic: Back then I created #2671 to just widen the Guava version ranges but even that failed and MWE was one issue. I'm not sure if it had worked if MWE would not use Guava, but I think it would at least be one step. The PR's I created so far are mainly to help to complete eclipse/mwe#287 which would already be one intermediate goal. |
When I look at my customer project, it’s hard to imagine how guava can be completely eliminated and it’s hard to see how that would concretely make the world a better place for them. It would most certainly have a significant development impact without a benefit seen by the end user. It might be the case that reducing the usage is a little like making it a little less pregnant. But pregnant is still pregnant. |
I don't advocate to generally replace Guava, I only suggest to replace it where are (more or less) direct replacement in the Java standard library. There are definitely cases where Guava provides valuables addition.
The situation does look so absolute to me. I think we can still reach intermediate goal that would be valuable. |
Guava is a dependency that's often difficult to handle (one reason is that Xtext is re-exporting it) and many of the enhancements Guava offered are part of the Java's standard library in recent versions. For the most commonly used elements in Guava there are often (almost) drop-in replacements or equivalent alternatives that are simple to migrate to. Many elements in Guava even recommend to use standard alternatives in their doc.
Therefore I want to suggest to replace Guava where it is possible.
In general the usage is split into two parts:
For APIs alternatives would have to be added and the existing methods would need to be deprecated for some time before they can be removed? This also relates to Xtext and (binary) backwards compatibility #2668 and should probably be handled together.
In general Guava is heavily used by Xtext, searching the
*.java
files in this repo forcom.google.common
gives 3535 hits. So replacing it is a major task and probably more a journey. At its end maybe Guava can even be dropped completely.But since it is hard to even get just a completely overview of its usage, my suggestion is to start with simple cases like replacing
Lists.newArrayList()
bynew ArrayList<>()
etc. only in internal usages and see how far we can get.The text was updated successfully, but these errors were encountered: