Java 8 – A Filter By Any Other Name Would Probably Smell Sweeter

I’m thinking the choice of name for the filter function in Java 8 steams was a really poor one.

I mean, what is a filter? Something that keeps things out, or something that catches the things we want?

Yes.

Dictionary.com has several definitions, from “any of various analogous devices, as for removing dust from air or impurities from tobacco smoke, or for eliminating certain kinds of light rays” to “to remove by the action of a filter”.

An air filter, we hope, will keep harmful airborne particles away. We also hope a filter in a sanitation plant will do similar work. (We should all know that the filter on a cigarette is only there for the sales pitch…)

I’m thinking gold-digging would use filters with the opposite purpose, but you pan for gold, don’t usually filter… I guess…

The guy that came up with the name “filter” might be a physicist and using this dictionary.com definition of filter: “Electronics, Physics. a circuit or device that passes certain frequencies and blocks others.”

But thankfully that’s not how the Streams-documentation suggests the filter-function should work…

Or the name was inspired by coffee filters? … no, wait, that’s very wrong!

Regardless…

Using the name “filter” for the function that will decide, like the gold diggers filter (that doesn’t really exist… ok, a physicist’s “circuit or device”… 😐 ) what to keep, seems very unintuitive to me, and I suspect it requires that you learn that in Javaspeak, “filter” means only one of the two possible definitions of filter (of which the “wrong” one seems über quasi… or like you take your coffee the very caffeinated way… with a spoon…)

I suggest adding “include” and “exclude” instead and then one of them (or both) can redirect to filter behind the scenes. (I’m inspired by Rsync…)

I’m thinking it should be quite hard to misunderstand those two. (And very hard to think using “filter” is a better choice)…

Writing programs in programming languages is, just as when you write in any other language, definitely communication with computers, other programmers and yourself in six months when you’ve forgotten what the hell the program code you’re staring at was supposed to do… And poor communication is the root of all evil and the end of all marriages… or so I’ve heard… 😀

I’m certain there are bugs out there right at this moment because of this language choice. (I’ll let you know how many of them are mine as I find them…)

(And by the way, the thing that catches the things you want is called a net, not a filter… maybe filter should be renamed to “net”? Since “catch” already is a keyword… :P)

In Touch with Reality

Generation X-er: Hey! iPhone zombie! How about you drop that thing and get in touch with reality?

 

Millennial: Yeah… I’m chatting with Ahmed in a bomb crater in Yemen… he wishes you’d get in touch with reality.

How About that Mathematical Proof that Women are Evil?

How about that mathematical proof that women are evil? It goes like this:

Women require time and money… (And I have the black eye to prove that’s all that’s needed… oh yeah… moving on…)

women = time \cdot money

Time is money (I’m just not able to find a bank where I can deposit my time, or even less get interest rate on it…)

time = money

So…

women = money \cdot money = money^2

Money is the root of all evil (which actually is pretty nice to money… after all, 4 money only gives 2 evil … or maybe that’s just to say evil is expensive?)

money = \sqrt{evil}

Which means that…

women = (\sqrt{evil})^2

Which then obviously means…

women = evil

Right?

Wrong!

I bet you’re the kind of person that didn’t pay attention in math class?

An example:

2^2 = 4

(-2)^2 = 4

So…

\sqrt{4} = \pm 2

Which means that in reality …

women = \pm evil

Women are evil… or not evil… which we kind of already knew without all this math.

Hah!