According to anti-if campaign it is a best practice not to use ifs in our code. Can anyone tell me if it possible to get rid of the if in this piece of code ? (switch is also
I don't think you are making a fair comparison here.
From the look of it the Anti-if campaign is just about practicing a better design approach.
However in your case you can see from all the above examples that if can not be removed from the surface and will always exist somewhere down in the center.
And why exactly is that?
Well If is a general purpose of life. I don't mean to say start coding if every where but in general without if there is no differentiation, if brings decisions and purpose, if that wasn't there then every object in the world would just execute as its suppose to without even knowing anything other then it self. And very simple you wouldn't have asked this question. :)