r/cpp • • Jan 15 '19

On C++ and Object Oriented Programming

https://marccgk.github.io/blog/on-c-and-object-oriented-programming/
1 Upvotes

13 comments sorted by

View all comments

3

u/utnapistim Jan 18 '19 edited Apr 01 '19

Even though C++ is described as a multi-paradigm programming language, the truth is that most programmers will use C++ exclusively as an Object Oriented language

[citation needed] (that is, I am a C++ dev who also uses free functions, lambdas, and structures - whatever is best for the situation at hand; my colleagues are the same).

The way I visualize an OOP solution is like a constellation of stars [...]. What worries me, though, [...]. As I see it, [...].

How can we measure all these opinions? Why are they authoritative on what happens in programming?

The fact that we’re “just” solving the immediate problem at hand should be good news but, in my experience, when using OOP design principles, programmers write a solution while shackling themselves to a commitment that the problem won’t change significantly and, therefore, the solution is permanent.

... unless programmers decide later to re-write / re-engineer the whole thing. I think this permanence is in the OP's head only.

I mean, from now on the solution is to be talked about in terms of the objects that form the constellation instead of e.g. data and algorithms; the problem has been abstracted away.

Yes, abstraction abstracts details away.

What is very clear to me, though, is that code will always degrade into chaos and disorder unless consciously fought against.

I’ve seen this take many forms in OOP solutions: [descriptions of hacked-together solutions]

Since OP is criticizing OOP here, but entropy is also present in non-OOP solutions, what forms does entropy take in those projects?

There’s a point in the lifetime of an OOP design where it has degraded to an untenable situation.

... as opposed to functional designs, where there is a point in the lifetime of the project, where it has degraded to an untenable situation.

...

... oh, wait!

Experienced programmers say that when your application has grown in size ten times over the original version, it should be rewritten anyway. This is not only particular to OOP.

There’s also the fact that OOP features are inherently poor performance-wise. I implemented a simple OOP hierarchy [...]

Contrived anecdotal evidence cannot be used to demonstrate a generic argument: the "simple OOP hierarchy" the OP implemented is not a demonstration of the general inefficiency of OOP. If anything, it demonstrates it was inefficient in the case the OP chose (to demonstrate inefficiency).

This is a straw-man argument.

Given that the job of a programmer is to solve problems using computers, it’s mind-boggling that so much of our industry cares so little about [...]

[citation needed]

I’ve had a lot of conversations about OOP and its inherent problems with different people and, although I think I’ve managed to convey why I think the way I do, I am not sure I’ve swayed anyone towards the non-OOP way. Maybe this post will help.

Invalid arguments sometimes change people's opinions. This is not a good thing.

“Good OOP wouldn’t do this.”, “This is badly designed OOP.”, “This code doesn’t follow OOP principles.” and similar variants. I’ve heard this one when showing examples of OOP gone bad (I’ve already talked about why OOP code invariably goes wrong). This is a clear case of the No true Scotsman fallacy.

The "No true Scotsman" fallacy is not a "clear case" whenever somebody discusses a good (vs. bad) solution. "OOP gone bad" is (maybe) good design, that has gone bad. That doesn't make it a fallacy, it makes it bad design.

I’m fully aware that identifying arguments as fallacies is not suficient to disprove their validity.

It is sufficient actually, when the fallacy is clear. In this case it just felt ambiguous.