Direkt zum Hauptbereich

Posts

Es werden Posts vom Mai, 2012 angezeigt.

The root of polymorphism: The Anti-If Campaign

Ever heard about the Anti-If Campaign ? The less if -statements there are in your code, the better -- argues Francesco Cirillo, the initiator of the Anti-If Campaign. There is a lot of truth behind his campaign. Too much if -statements in your code are evil, that's for sure. They'll make your code static, hard to maintain and no fun to read. It goes without saying that related concepts like switch-statements, conditionals and the like are subsumed under " if ". They are just syntactic sugar for a certain arrangement of if -statements. I asked myself: What if we abandon if -statements completely? What about being absolutely strict about the use of if  and related concepts: No if s in your code anywhere anyplace. You are not allowed to use if  at all. It is like not having such a construct in your programming language. Is it possible to write code without if s? Yes, it is, as I'll show in this post. You'll end up with polymorphic functions instead -- and thi