r/java • • Apr 10 '26

The Best Library Might Do Less

https://martiansoftware.com/articles/the-best-library-might-do-less

I wrote a short post about something I think about a lot when writing or evaluating libraries. For me that usually means Java libraries, but the ideas aren't Java-specific.

It describes how I think about a library's "value" in the usefulness sense, and how libraries can go too far and become less useful. I thought it might be helpful to pull those ideas together in one place.

Rereading it myself, I also noticed it lines up pretty well with the Unix philosophy.

21 Upvotes

14 comments sorted by

View all comments

12

u/kevinb9n Apr 10 '26 edited Apr 11 '26

This is a good explanation of some very important advice. We took this approach with Guava. Yes, I know it's not a small library, but size != complexity. We adopted Josh Bloch's mindset of power-to-weight ratio. We evaluated new APIs for what we called "utility times ubiquity": they need to be pretty useful a LOT of the time, or VERY useful just enough of the time.

Don't sacrifice your ability to give your 90% use cases their best possible experience just because the 91% user shows up in the conversation. Their arguments will be very compelling. It takes strength to keep saying "sorry, this class just isn't going to do that". If you don't deeply believe in the value of your library as it is, in the importance of maintaining its simplicity, you might well crack and give in to their (very compelling) request.

(EDIT: I also co-created an old thing you basically don't need anymore called AutoValue. There was another tool that published a feature comparison grid between AutoValue and itself, where it had like 53 check marks and AutoValue had about 6. I was so proud of that grid.)

4

u/martylamb Apr 10 '26

Thanks - and your Guava examples are exactly right IMO. If something is well-designed and consistent, it can be a "large" library in the bytecount sense but still very "cognitively small."

Their arguments will be very compelling. It takes strength [...]

Indeed!

(and thanks for the great Java tools!)

3

u/agentoutlier Apr 10 '26 edited Apr 10 '26

One of the key things I liked about Guava is by far being one of the first libraries besides the JDK itself that expects you not to pass null in and if you do it is mostly an error.

I know many younger developers perhaps now think this expectation was originally the default but in the early years like Apache Commons null in and null out aka passing the buck was the default.

And if you think about it that old logic of defensive programming of dealing with null by returning null adds complexity. Even in my first jobs I was guilty of writing things like if null is passed in then null is returned over and over in javadoc comments.

Likewise in the early years (I'm talking like the early/mid 2000s) explaining closures or functional like programming to my Java developer peers who often came from C or other imperative languages difficult. Guava made the rationale of FP where you really need lazy transformations easier to explain to my fellow colleagues and while I'm all for for loops transforming iterables or iterators can be less complex to explain (even if underneath it is more complex). In other words good abstractions make things simpler to understand and combine and Guava has lots of that.

(EDIT: I also co-created an old thing you basically don't need anymore called AutoValue. There was another tool that published a feature comparison grid between AutoValue itself, where it had like 53 check marks and AutoValue had about 6. I was so proud of that grid.)

I think more people should embrace writing their own annotation processors in the same vain that if you are using a Lisp you should use the power of the macro engine for your own domain instead of always reaching for some library particularly in the case of ease of factories. That way you can keep it simple and not have annotations with 100s of options.

2

u/Jon_Finn Apr 12 '26

One of the most important times I've used Guava was (early on) for the Guava Cache classes. I loved that what was (presumably) a very complicated implementation, with various setup options in a builder which might have been achieved via loads of public classes, instead has a small and simple public API.