Thursday, April 8, 2010

.not is EVIL!

What's a .not?

.not is a decorator method that decorates the object, so that the boolean method call that immediately follows the not call is negated. For example, if self.is_italic? returns true, self.not.is_italic? returns false.

Why would people use .not?

The only reason I have heard so far is because it sounds more like English...Pffft, sounds more like English!

Person.find_by_name("Paul Frank").not.is_popular?

How is that anyway similar to English: Is Paul Frank not popular?

What's wrong with logical negation '!' ? The only reason I have heard so far is that it's at the head of the statement, and with long condition, it falls off the screen... Pffft, falls off the screen!

First, I don't believe in reinventing the wheel that is worse than the original one.
Second, instead of using a CPU to flip a bit, we malloc the heap, create an object, extend some other object with this object, which alias the method to use a CPU to flip the flipping bit!
Oh, did I mention it's stupid?

In addition to that, .not is broken. In any given object, you cannot call .not on the boolean variable.

Class Person
@humorous = false;

def foo
@humorous.not #=> is not going to do anything!
end
end

More over, what prevents someone from doing foo = bar.not, and a thousand lines later, some other call foo.is_real? without knowing that it is being 'notted'?

So you cannot get rid of ! anyway. The best you can do is use the not operator to avoid !, then you have precedence problem to think about.

People then say oh who cares, how many CPU time do you use over that? I'd rather have more style than looking like C.

Well, you see, you don't usually run around a building complex just to go from your desk to the break room 25 feet away, even though it doesn't affect one bit the history of mankind. You don't do that because it's stupid. Oh, and did I mention .not is stupid in exactly the same way?

! has been around since the dawn of computer programming. Whoever thinks ! is not readable should quit programming and do some research on herbal hair gel. If your condition is way too long for you to see ! on a 24" 1080p widescreen, it's a code smell that you should rethink your logic, or model design in general. Whoever thinks ! is ugly and remind them of C should appreciate their own breadth of knowledge, and that without C there is no .not, and the fact that languages are means, not the goal.

Remind yourselves to always do the simplest thing that makes sense. .not is not simple, and not making much of a sense either.
\No new line at the end of file.

1 comment:

Harbor Sparrow said...

I agree, it's totally sick.