In this tutorial, i will show you the reason why Use “Switch” Is Not an Anti-pattern. Let’s take a lesson from functional programming to find when using a switch is OK.
I have seen several articles recently that take the position that
switch statements (or even
if statements) are an anti-pattern in regards to best practice object-orientated programming. In a way, the sentiment is usually fine, but I don’t think that these articles really tell the full story. Let’s take a lesson from functional programming to find when using a
switch is OK.
I’ll use TypeScript in this article as it supports all of the necessary language features and is usually pretty easy to read.