08 Jan 2013, 22:50

If-less programming

An interesting article : "If-less programming", which can be summarised in do less if statements in your code and use object oriented features instead.

As quoted in the article :

An “if” statement is an abomination in an Object Oriented language. Why? Well, an OO language is composed of classes, objects and methods, and an “if” statement is inescapably none of those. You can’t write “if” in an OO way. It shouldn’t exist. Conditional execution, like everything else, should be a method. A method of what? Boolean.

For example, polymorphism or subclassing could replace some/most of if statements.

I recommend you to read the article to have a loot at the examples and have an opinion.

Of course, it's not about to replace all your if statemetns by objects but at least you can rethink your code with this in mind ;-)