I recognize the impact on downstream users (we all are or have been
downstream users at some point), so I'll present a simple case.
Take the following comparator, from ColumnHelper, for example:
private static class CTColByMaxComparator implements Comparator<CTCol>
{
public int compare(CTCol arg0, CTCol arg1) {
if (arg0.getMax() < arg1.getMax()) {
return -1;
} else {
if (arg0.getMax() > arg1.getMax()) return 1;
else return 0;
}
}
}
I wanted to minimize the number of calls to getMax(), because it is a
proxy method which does synchronization among other XMLBeans voodoo - this
is related to some of the performance issues related XMLBeans I'm trying
to improve, and exists in many examples elsewhere.
With Guava, this comparator can be defined like this:
private static class CTColByMaxComparator implements Comparator<CTCol>
{
public int compare(CTCol arg0, CTCol arg1) {
return Ints.compare(arg0.getMax(), arg1.getMax());
}
}
Obviously, this serves two purposes:
1) The code is much shorter and readable - providing an quicker grasp of
logic.
2) The redundant calls are minimized as their results are passed as
arguments.
Without Guava (or a similar utility method) an optimized version would be
defined like this:
private static class CTColByMaxComparator implements Comparator<CTCol>
{
public int compare(CTCol arg0, CTCol arg1) {
long col0max = arg0.getMax();
long col1max = arg1.getMax();
return col0max < col1max ? -1 : col0max > col1max ? 1 : 0;
}
}
If we were using Java 7, we would be able to use Integer.compare() instead
of Guava's Ints.compare(), but that's another upgrade path that's probably
too early to consider...
This is just a simple example, but still good for a general discussion of
dependencies.
Yaniv
-----Original Message-----
From: Nick Burch [mailto:[email protected]]
Sent: Thursday, August 7, 2014 13:15
To: POI Developers List
Subject: Re: Adding Google Guava as a dependency
On Thu, 7 Aug 2014, Andreas Beeker wrote:
> In the discussion of having new features (incl. new dependencies) and
> not to have them, mostly the second part wins, as "POI is included in
> quite some other projects where the new dependency (version) could
> interfere".
>
> I think, at least for the test stuff, this shouldn't be a problem ...
I know it might not be quite such fun, but I'd vote for trying guava out
on tests first. Adding a new dependency to core is a potentially big deal,
with large effects on most of our downstream users. Adding dependencies to
test is fairly easy.
If we could start out with some improvements to tests with Guava, that'll
help everyone see the benefits, and get comfortable with it, without
impacting users. That will also mean that if we do all decide to roll it
out to the main code too, we've a strong case to use to justify it to
those users who complain (and trust me, there will be a number of users
who'll complain...)
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]