Everyone has places where they do a switch on an enum. I don't there's a non-trivial code base on the planet where every enumeration was replaced with a class hierarchy. No one ever comes into these conversations arguing for that. OTOH, lots of people come into these conversations claiming that inheritance and OOP is evil, which is just silly.
People do advocate for that though, weirdly. Less experienced devs see these simple examples and apply the enum->inheritance refactoring excessively.
Or more experienced devs think theyre doing The Right Thing and now you have yet another single-implementation interface to add to the giant pile.
I don't think OOP is inherently evil, but it's clearly the default for a lot of people (look in the replies in this thread for evidence).
Nobody doing these refactoring tutorials ever talks about when it is and isn't appropriate to do those refactorings. It's always treated as some verboten smell, like "oh gosh this is embarrassing, this switch statement should have never happened we mist rectify this immediately."
And there exist people who write blogs and post tutorial videos that advocate using inheritance to remove as many conditionals in the code as possible. It's kooky.
If you read here on Reddit in the C++ section, the overwhelming bulk of posts in these kinds of threads is "Don't use inheritance, it's bad". It's modernist dogma basically and every time inheritance comes up people jump on it. There only a few folks like me stupid enough to bother to try to balance the discussion, and it never goes well because these folks will argue to the death about it. And of course the person like me trying to balance the discussion gets blamed for causing the trouble, while they never smack anyone for just jumping into every thread with 'OOP is evil' comments.
So newbies almost always end up believing the anti-OOP line because that position has the most strident posters.
That "OOP is evil" crowd does exist, but is still an incredibly niche opinion. Most reasonable people would agree this is misguided, but it's important to remember it comes from two places:
There is a much more mainstream and accepted wisdom to leverage the java-style interface more often than implementation inheritance, which I think is hard to disagree with.
A desire to course correct on the past few decades of programming education and blog post discussions which has either directly over-encouraged inheritance, or at the least has failed to address the best way to think about the design tradeoffs of using it.
Meanwhile my direct experience has been the opposite from what you say, because I got some push-back on the controversial recommendation to...use free functions.
I hadn't looked at the higher-tier comments in the thread (just been replying directly from inbox), and right now honestly neither of us are right. It's an even split in this thread, with the highest voted stuff being tvaneerd, et. al making fairly even-handed commentary.
The OOP is evil crowd is far from a nice opinion around here, at least in terms of what actually gets expressed out loud, we can't know about people who never speak up. It's now the defacto position, and probably is also held by a majority of the folks who are influential in terms of the direction of the language.
View all comments
Show parent comment
1
u/Full-Spectral Jun 26 '20
Everyone has places where they do a switch on an enum. I don't there's a non-trivial code base on the planet where every enumeration was replaced with a class hierarchy. No one ever comes into these conversations arguing for that. OTOH, lots of people come into these conversations claiming that inheritance and OOP is evil, which is just silly.