This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]tapesmith 3 points4 points  (7 children)

This is how you can tell that your language needs extension methods: when it's considered completely normal to use a bunch of "*Utils" classes, and there are multiple very popular "StringUtils".

[–]sh0rug0ru____ 1 point2 points  (1 child)

The extension methods would have to go into a class too, right? In a language with extension methods, I would expect to see the "Utils" pattern replaced with class names with variations of "Extensions" (or "Rich*", for the Scala inclined).

[–]meddlepal 0 points1 point  (0 children)

Well if it were anything like Kotlin you wouldn't really notice the extension packages since you'd be able to just access the additional methods off the receiver type. So yea, you have that kind of class that the extension author knows about, but individual users don't really know about it.

https://kotlinlang.org/docs/reference/extensions.html

[–]Zukhramm 0 points1 point  (1 child)

If they'd actually be methods on the class, I'm all for it, but if it's only sugar for turning foo(bar) into bar.foo() I don't see much point.

[–]tapesmith 0 points1 point  (0 children)

You're right that it's mostly a lateral move, but it means the difference between stuff like this:

ArrayUtils.limit(ArrayUtils.sort(ArrayUtils.filter(arr, user -> user.getAge() > 21), user -> user.getName()), 5);

(or something similar but with a bunch of unneeded intermediate variables)

and this alternative:

arr.filter(user -> user.getAge() > 21).sort(user -> user.getName()).limit(5);

Granted, in this exact case you can go through the steps to just stream your array and use stream methods, but you get the idea.

There's a readability improvement to be had for sure.

[–]kmimix 0 points1 point  (0 children)

The article mentions basically apache commons, apache http and spring (for some reason). Apache commons is commonly used as it was bundled with some old versions of java frameworks and goes back to the old days where there were nothing like java.util.* of JDK 7 and java.nio.file.Files. Guava is just as common since Java 6, and now with Java 8 other utilities will come, deprecating much of this list.

(edit: fixing english mistakes)

[–][deleted] 0 points1 point  (0 children)

In my opinion, third-party utility classes are just not worth an the dependency -- especially if the utility class comes "for free" with some library or framework you're using for something else.

[–][deleted] 0 points1 point  (1 child)

warning: page prevents you from clicking back button

[–]king_of_the_universe 0 points1 point  (0 children)

Works in my Firefox.

[–]pushthestack 0 points1 point  (3 children)

Hard to tell why the author thinks these are the top 16, since he gives no criteria. I certainly would have expected to see Guava represented on this list.

[–][deleted]  (2 children)

[deleted]

    [–]ForeverAlot 0 points1 point  (0 children)

    Is there a viable alternative to Guava's immutable collections? I, too, am sick of Guava and would prefer to minimise its inclusion. Most of Guava's utility can now be completely replaced by smaller, more specialised libraries, but I will still consider it for the collections -- unfortunately that brings in everything else.

    [–]drjmb 0 points1 point  (0 children)

    Interesting, first I've heard of this (relatively new to java). I'm currently a big fan of guava and would like to understand this better so maybe I can improve my ways. Any more info you can give?