Commons-io: By retards, for retards
A week or two ago yet another Jakarta commons project was inflicted on a largely unsuspecting world. This release didn’t so much as arrive with a bang or make an entrance, it sort of guiltily snuck in hoping no one would notice.
If you were to have a look at the contents of this latest abomination, you’d realise why it’s guilty and ashamed from the outset. Let’s take a brief walk through this remarkable insight into the mind of a a happy idiot java beginner. Yes folks, most of you too were this stupid and ignorant once, so let’s not judge these genuises too harshly.
First up, we have the standard open source pointless class syndrome. This seems to be a vital requirement for any open source project; a bunch of classes that explicitly do sweet fuck all. In commons-io, these take the form of True/FalseFileFilter. Wonderful file filters that always pass and always fail, just what your project needs.
Stepping back a little, one has to wonder at whether the world really, really needs a file filter package whose sole purpose is to bring together the built-in FileFilter and FilenameFilter. These works of wonder take up 13 classes of the 34 in the whole jar. The whole premise is somewhat ridiculous, anyone who cares a whit about performance, encapsulation, or readability would NOT build up file filters by contorting their code into bizarre shapes just so they can do something like new OrFileFiler(new NameFileFilter(), new AndFileFilter(new TrueFileFilter(), new NotFileFilter(new FalseFileFilter(), new SuffixFileFilter())));. At the risk of being controversial, might I suggest doing what any sane person would, and just writing your own goddam filter that does exactly what you need it to?
If only the horror ended there. When these clever kids were taught Java, nobody bothered explained the standard API to them, or how it contains an awful lot of handy-dandy classes that one need no re-implement. Witness the genius of BufferedOutputStream! commons-io of course ignores that, and includes the inspired DeferredOutputStream. What does it do? Why, it buffers, but only once! Latter chunks are no longer buffered! Still, they should be forgiven, as this functionality is something that all of us regularly make use of, I mean, who DOESN’T need a stream that has one buffer chunk then starts streaming?
Unconvinced yet? Well, here’s the crowning glory of this package of congenital defects. IOUtils.toByteArray(String). The more perceptive and java-savvy amongst you might remember that String already has a getBytes method. Oh well, I guess that’s what they call in the implementation. Not so! They instead creating a byte array output stream, write the string into it, then return the contents of the stream as byte[]. Why oh why weren’t these people taught that strings are immutable? Why did nobody think to point out to them that if you modify the byte[] of a string.getBytes(), the string itself is unaffected? Of course, let’s not shame these Jakarta folk any further by being pedantic and mentioning that converting a String to byte[] is pretty silly if you’re not going to take encodings into consideration (needless to say, they’re blissfully encoding ignorant all over the API).
It’s easy to laugh at these wankers and dismiss them out of hands. That’d be irresponsible though. As adults and contributors to Java it is our job, nay, our duty! to educate and help these poor souls. So do the world a favour. Find the nearest Jakarta committer, and beat him like a red-haired bastard child he most likely is, while explaining to him the java fundamentals. Maybe this time round they’ll stick.
Oh and for those of you desperate for more JBoss goodies:
From: "Nathalie Mason"
May 27th, 2004 at 3:46 pm
A most detailed investigation.
The Filter issue is your own personal coding choice, bespoke vs lego. I’m with the lego.
DeferredOutputStream will be asked to justify its existence, as will the IOUtils.toByteArray method.
Finally, I’ll have you know that per dictum #1267, by order of the chair, red-haired Jakarta committers have dyed their hair blonde.
May 27th, 2004 at 3:51 pm
http://jakarta.apache.org/commons/io/
shame on you Hani :)
May 27th, 2004 at 4:30 pm
The IOUtils class, which has only static members states this in its constructor:
“Instances should NOT be constructed in standard programming.”
Do I need to point out that the constructor is public?
May 27th, 2004 at 4:52 pm
The reason for the public constructors is because scripting tools like Velocity have problems calling static methods. They have to invoke methods on an instance, even if the methods are static.
I’m not even sure if this is still true (about Velocity) but I think that this is the reason.
May 27th, 2004 at 6:39 pm
Avoiding copypaste, what would you choose?:
1. programing macros in a static class? (***Util)
2. programing a new Class with one method? (for thread safety)
3. programing/using a codegenerator that does the copypaste at build-time?
4. programing a good structured design?
5. programing a good oo design?
6. use a commons-**** package?
May 27th, 2004 at 7:26 pm
now
thats
what a bile should look like :)
May 27th, 2004 at 7:39 pm
While you’re being pedantic, it’s “dismiss them out of hand”, not “dismiss them out of hands”… unless, of course, you were doing a bad wanker joke… but anyone who needs both hands to wank is either doing it wrong or really shouldn’t be wanking.
May 27th, 2004 at 9:20 pm
if they wanted to be useful, a toCharArray() that deals with char encoding properly would have been great (unicode can be a minefield to the unwary).
I have to profess though, the rest of IOUtil is pretty handy, its very easy to fuck up those pesky Reader->Writer kind of operations in weird and wonderful ways…
May 27th, 2004 at 9:24 pm
duh, they did! scuse my ignorance, but the copy(*) methods take encodings as args or use the default if unspecified. oh well, back to my hole…
May 27th, 2004 at 9:39 pm
one last thing [haven't learnt yet, probably should post with a pseudonym] re. immutable Strings … on oldie but a goldie:
public String getAString() { //get a reference to the private field value in String class. java.lang.reflect.Field stringValue = String.class.getDeclaredField("value"); //make it accessible stringValue.setAccessible(true); //unsuspecting string String sittingDuck = "sittingDuck!!!!!"; //black magic happening here stringValue.set(sittingDuck, "hastaLaVistaBaby".toCharArray()); //guess the output of this! return "sittingDuck!!!!!"; }apparently this has been fixed in some recent JDK, but not sure which… doesn’t affect getBytes() but, which I have just noticed ALSO has char encoding support … dang I’m slow today!!! [note to self, NEVER post under real name the day after a big rehearsal]
May 28th, 2004 at 9:24 am
hani-
if I remember properly, you wished for the existence of such a device in a previous bile. this might be something for you:
Printer which takes in toilet paper
May 28th, 2004 at 11:02 am
>but anyone who needs both hands to wank is either >doing it wrong or really shouldn’t be wanking.
>
>Posted by fletch at 27.05.2004 19:39:46
OR has a really BIG FAT CLOWN!
May 28th, 2004 at 11:03 am
What’s encapsulation and information hidding?
“Though the code may use Java objects, it does so in a manner reminiscent of a by-gone era: utility functions operating on data structures. Welcome to 1972!”
May 28th, 2004 at 11:09 am
What is does “immutable” mean?
Sorry for my poor Engrish. I am from Pakistan where we murder each other over 100 rupees.
May 28th, 2004 at 11:54 am
Shame on you! Not everyone in the world is as healthy and fat as pigs like Americans.
Sorry for my bad English. I’m from Indonesia, where all candidates running for presidency can all go to hell … especially Amien Rais (fuck you!), except Susilo Bambang Yudhoyono (yay! Good Old Nationalist Military Figure — kick away those retarded religious candidates)
> What is does “immutable” mean?
> Sorry for my poor Engrish. I am from Pakistan > where we murder each other over 100 rupees.
May 28th, 2004 at 11:54 am
Oopss… I mean Wealthy. That proved my bad English.
May 28th, 2004 at 12:27 pm
I said I am from Pakistan. I am thin as toothpick.
I still want know now what mean “Immutable”?
Sorry for by mad English. I am from the pit of the arm Rawalpindi. We have no immutables.
May 28th, 2004 at 3:02 pm
From the out sight, Apache looks good. and true,some of them may be good.
But with so many utils crap around, it really sucks now a days.
Yeah, how about somebody releasing an util library to wrap up all the fu**ing utils around??
Why the hell on earth, these people should leave the programmers to do the job? If somebody cannot do even a code to use string properly, why the hell on earth, they should be paid as programmers?
Sucks is the milder word!
May 29th, 2004 at 3:11 am
While Henri likes his Lego, I think he’s playing with it on his own. Does anyone actually use these Jakarta bollocks in their products ? I mean, do you insist that your users will have to download this filth or do you just write what you need since it takes so little time to do it?
May 29th, 2004 at 6:21 am
There are some real gems available from the Jakarta project. My personal time saving favourites are the simple and effective org.apache.commons.lang.builder.HashCodeBuilder and org.apache.commons.lang.builder.EqualsBuilder.
I wouldn’t be without them.
June 4th, 2004 at 5:10 am
http://trijug.org/downloads/JBOSS1.ppt
crazy & funny & pathetic
June 22nd, 2004 at 6:35 am
Yeah, right, time saving. Till the day you realize that the company app server has restricted relflection capabilities and you end up writing the same old bull hashCode methods anew.