Wim Jongeneel
2 min readAug 22, 2021

--

I don’t want to say you’re outright wrong, but I think you are connecting the wrong conclusions to good things. In essence, OOP has nothing to do with if-statements or avoiding them. If-else is a construct from the structural programming paradigm, where it is responsible for logical branching. Structural programming, as the name gives away, is programming with structures: if, if-else, for, while-do and do-while. Object-oriented programming in its turn is programming with objects and messages between them.

So you are right that any OOP code does not contain any if-statements, but that isn’t because OOP has no logical branching. You just don’t use an if-statement. Instead you have a True and False class that both inherit from Bool and implement methods like IfTrue and IfFalse. With those you can make the exact same branching, only in a different way. And that is what those paradigms are about: not doing something different, but doing the same in a different way.

The fact that you still have if-statements in C# is because C# isn’t a pure-oop language. It is a multi-paradigm language that incorporates OOP, structural programming, functional programming and even a bit of logical programming. If you are using classes and OOP design pattern as your hammer for every problem in C#, you are missing out on a huge part of the language.

You are right that good code is low on branching, but again, that has nothing to do with OOP or even design patterns. It just means that you came up with a simpler solution for the problem that utilized the tools you have. The exact same thing is true for functional programming, logical programming, procedural programming etc. “Less logical branches is better” is an universal design truth and has not so much to do with what paradigm you are using. It is also a design problem, not an implementation problem. If I read articles like this then you are so overly focused on implementing things that you forget to design the solution first. And that leads to the ridiculously overcomplicated code that many people are hating on in your comments. It is not that the ideas per se are bad, but the lack of nuance and context turns good ideas into bad extremes.

If I may give you some advice: take a step back from hammering things in C# and widen your knowledge outside the class-based programming languages. I don’t doubt you know a lot about that exact one thing, but you are also totally missing the why, how and when of object-oriented programming.

--

--

Wim Jongeneel
Wim Jongeneel

Written by Wim Jongeneel

Software Engineer at Mendix (Rotterdam, The Netherlands) • Student MSc Software Engineering • Functional programming enthusiast

No responses yet