News for hackers. Stuff that matters.
Re:The Anti-If Campaign by J_McQuade on Thursday June 25, 2009 @10:58AM (#673740)
This sort of debate annoys me - not so much because of the potentially fragile design on one side or the perhaps pedantic adherence to OOP principles on the other, but because I know that I could have things like pattern matching and a scarily expressive type system and, well, that'd make a lot of these problems disappear.

Curse you, Haskell, for making me so bitter!

Re:The Anti-If Campaign by tptacek on Thursday June 25, 2009 @11:19AM (#673789)
This is a joke, right? They're making fun of all the programs you see that have 20 different forests of tiny classes spreading the logic of one function across 45 files, right?
Re:The Anti-If Campaign by erlanger on Thursday June 25, 2009 @11:31AM (#673817)
You mean Lussumo?
Re:The Anti-If Campaign by calambrac on Thursday June 25, 2009 @10:51AM (#673725)
Don't solve with conditionals that which can be solved by your language's dispatch mechanism.
Re:The Anti-If Campaign by tptacek on Thursday June 25, 2009 @11:30AM (#673814)
Don't solve with 15 minutes that which you can bill your client 80 hours for.
Re:The Anti-If Campaign by calambrac on Thursday June 25, 2009 @12:34PM (#673958)
In retrospect, my comment sounded like it was reaffirming the article's point, but that's really not how I meant it (snark fail on my part).

I agree with what you're getting at, and I think that the idea of popularizing "AntiIf" as a slogan is really stupid and dangerous. The first eager intern who suggests refactoring some code because "ifs are bad", I'm not a religious man, but God help them.

What I was trying to point out is that the single example they have up right now showing that 'if' is "bad" is dispatching on types, which a good number of languages support out of the box (in other words, it's a strawman). If you're already inspecting types, then they presumably already exist, so there's no additional overhead in using your language's features to get clearer code when you can.

Re:The Anti-If Campaign by stcredzero on Thursday June 25, 2009 @11:42AM (#673840)
And don't forget, lots of those 15 minute intervals can add up to serious money. ("Stovepipe" systems.) You can also set up an opportunity to bill for coming later in and "fixing" a seemingly intractable big mess.
Re:The Anti-If Campaign by tptacek on Thursday June 25, 2009 @12:01PM (#673882)
"Oh, I see the problem right here, Mr. Client. Your previous consultant used 'if' statements. Here, let me replace that function with 80 new class files. You'll be much more agile!"
Re:The Anti-If Campaign by stcredzero on Thursday June 25, 2009 @12:13PM (#673911)
I find that the opposite is true: replacing lots of runtime type identification with polymorphism results in placing repeated code in just one place. Don't Repeat Yourself is more agile. Even better: wait until at least the 3rd repetition before refactoring. (But don't wait too long.) This cuts down a lot of unnecessary coding, and leaves the programmer some leeway for good judgment.
Re:The Anti-If Campaign by Confusion on Thursday June 25, 2009 @11:54AM (#673864)
Do not attribute to malice what can be equally well explained by stupidity.
Re:The Anti-If Campaign by stcredzero on Thursday June 25, 2009 @12:14PM (#673913)
Malice has a better chance of sustained profitability.

EDIT: This is a clue to bad intent. "Follow the money!"

Re:The Anti-If Campaign by stavrianos on Thursday June 25, 2009 @12:28PM (#673943)
and yet, the world over, people are still both basically decent and basically stupid.

Edit: correlation?

Re:The Anti-If Campaign by scott_s on Thursday June 25, 2009 @10:49AM (#673720)
Oddly named campaign to promote better use of inheritance. "The Anti-Type Fields Campaign" would be more appropriate and less confusing.
Re:The Anti-If Campaign by tptacek on Thursday June 25, 2009 @11:31AM (#673816)
It's not about type fields and tag-and-switch. It's about the "if" statement. Let's be clear about how batsh*t crazy this messaging is.
Re:The Anti-If Campaign by scott_s on Thursday June 25, 2009 @11:35AM (#673824)
If you read their content (what little there is), it's type fields that they actually object against. I don't think they're actually saying "remove all ifs from code." If they are, then, yes, that would be batshit crazy. Instead of being crazy, though, I think they're just ineffective at communicating their message.
Re:The Anti-If Campaign by davidw on Thursday June 25, 2009 @03:48PM (#674270)
With pattern matching, you actually end up being able to mostly do away with if and switch statements, so it's not completely as crazy as it sounds. OTOH, sometimes pattern matching involves a lot of "repeating yourself", where you have to retype the function name, and a bunch of arguments, and only one changes.
Re:The Anti-If Campaign by tptacek on Thursday June 25, 2009 @11:59AM (#673877)
I agree with you: it's the messaging that's batsh*t crazy, not the idea.

The idea is just bad.

Re:The Anti-If Campaign by henning on Thursday June 25, 2009 @11:09AM (#673764)
Inheritance or polymorphism?
Re:The Anti-If Campaign by davidw on Thursday June 25, 2009 @11:15AM (#673780)
calambrac gets it right: 'dispatch'. I though the article was going to be about pattern matching, actually. I guess polymorphism is a sort of pattern matching, but the real thing goes farther.
Re:The Anti-If Campaign by scott_s on Thursday June 25, 2009 @11:14AM (#673775)
Polymorphism. I knew just saying "inheritance" didn't feel right. Thanks.
Re:The Anti-If Campaign by gabeybaby on Thursday June 25, 2009 @01:33PM (#674077)
I think this "campaign" is aimed at a developer less capable than the crowd we see on HN. I used to work with a whole team of people where OOP is a strange concept. I think the Anti-IF rule can help people think in a more correct fashion if they're confused about Inheritance.
Re:The Anti-If Campaign by wglb on Thursday June 25, 2009 @12:57PM (#674015)
These days, I tend to use COND rather than IF.

Ah, but the page implies use bunches of teeny classes. Was that what Alan Kay had in mind when he coined "Object Oriented Programming"?

Re:The Anti-If Campaign by jrandom on Thursday June 25, 2009 @12:50PM (#674000)
This strikes me as particularly funny as I'm working on a module of code where I had to use a type field and an 'if' statement to get around a dynamic cast that was killing performance.

(Virtual functions were not an option as this was taking place inside an STL '==' comparator.)

Re:The Anti-If Campaign by aheilbut on Thursday June 25, 2009 @11:43AM (#673841)
after vanquishing all if statements, we're going to go after function calls.

And after that, we will eliminate source code, because it's too complicated. Everything you need to do can be done with 5x7 index cards.

Re:The Anti-If Campaign by tptacek on Thursday June 25, 2009 @12:02PM (#673884)
First they came for the function definitions, and I said nothing, for I used lambdas.