Elimination of Conditional Logic

More often than not, a high frequency of the message `ifTrue:ifFalse:` suggests that distinctions which might have been possible at design time are being drawn at run time. But if distinctions were drawn at design time in the form of classes, then it would not be necessary for the running program to repeatedly rediscover what was known by the developers.

This leads to conclude that drawing design time distinctions at run time is intention obscuring by nature. It is a sign of missing explicit representation of valuable distinctions, of information kept private in the developer’s mind. It is also the manifestation of unnecessary homework left to any reader of the code. This is because classes are explicit consequences of the intentions behind their existence.

From a more pragmatic point of view, what is even worse about this homework is that it applies to the virtual machine as well. Drawing design time distinctions at run time takes computer resources which could be more wisely spent.

Polymorphic message sends allow the meaning of messages to be defined by the context in which the message is received. Therefore, in programs in which design time distinctions are drawn explicitly as classes, `ifTrue:ifFalse:` tends to become unnecessary.

If you need to improve performance, classes and polymorphism are some of your most powerful allies because they can make it so that the run time does not need to spend any time whatsoever recreating known information.

The assertion that more classes can result in improved performance may seem strange at first. However, it is the case that virtual machines make large systems of objects evolve faster and more efficiently when behavior depends heavily on polymorphic message sends rather than on ifTrue:ifFalse:. This is because virtual machines are well equipped with machinery that executes polymorphic message sends extremely fast. Therefore, let go of the temptation to do the work of the virtual machine by invoking special messages such as `==`, `isKindOf:` and `ifTrue:ifFalse:`.

In short, *distinguish* and *conquer*.

> You can only name what is already distinguished.

An excellent example of using polymorphism to avoid drawing unnecessary distinctions at run time, and of letting the meaning messages be defined by the context in which they are received, is how `true` and `false` themselves are implemented.

[…]