The day I learned that Linus shares my disdain for all things OOP was such a good day for me.
I feel the OOP debate got a bit out of hand. I hate OOP as well, as a paradigm.
But I love objects. An object is just a struct that can perform operations on itself. It’s super useful. So many problems lend themselves to the use of objects.
I’ve been writing a mix of C and C++ for so long I don’t even know where the line is supposed to be. It’s “C with objects”. I probably use only 1% of the functionality of C++, but that 1% is a huge upgrade from bare C IMO.
I think the problem with OOP is something you can see whenever legislation is linked with prestige (it happens a lot in real life). The number of good possible rules is quite limited, and the number of people who want to make a name for themselves by championing them seems to be infinite. If you can’t find a good rule to claim as your own, you have to pick a bad rule and try to gaslight people into thinking it’s a necessary and beneficial. Enough people do that, and we end up with modern OOP.
Agreed. Objects are nice and a great way to program. Composition is great. Traits/interfaces are great. Namespaces are great. Objects are a really nice way to reap the benefits of principles like these.
But then there are aspects of OOP that absolutely suck, like inheritance. I hate inheritance. The rules get very confusing very quickly. For example, try understanding overriding of methods. Do I need to call the superclass method or not? If not, does it get called automatically? If so, in what order? How do these rules change for the constructor? Now repeat this exercise for every OOP language you use and try not to mix them up… Java, C++, Python, etc.
Fortunately, it feels like we rely on inheritance less and less these days. As an example, I really like how Java allows you to implement Runnable
these days. Before, if you wanted to run a thread, you needed a separate object that inherited Thread
. And what if that object needs to inherit from another one too? Things would get out of hand quickly. (This is a very old example, but with lambdas and other new features, things are getting even better now.)
Anyway, long story short, I think OOP is a complicated way to achieve good principles, and there are simpler ways to achieve those principles than a full OOP implementation.
I’ve seen this thing where people dislike inheritance a lot, and I have to admit that I kind of struggle with seeing the issue when it’s used appropriately. I write a bunch of models that all share a large amount of core functionality, so of course I write an abstract base class in which a couple methods are overridden by derived models. I think it’s beautiful in the way that I can say “This model will do X, Y, Z, as long as there exists an implementation of methods A, B, C, which have these signatures”, then I can inherit that base class and implement A, B, and C for a bunch of different cases. In short, I think it’s a very useful way to express the purpose of the code, without focusing on the implementation of specific details, and a very natural way of expressing that two classes are closely related models, with the same functionality, as expressed by the base class.
I honestly have a hard time seeing how not using inheritance would make such a code base cleaner, but please tell me, I would love to learn.
He is is OK with OOP. The Linux kernel is full of OPP C, but he doesn’t like C++
I think Linus did it in C with GTK but who took it moved it C++ and Qt. Lazy searching didn’t dig up the story.
Look at the kernel code. It’s full of OOP C. There absolutely are objects in the kernel.
Me, when Linus’ opinion is different to mine: “Linus has such weirdly strong opinions about this”
Me when Linus’ opinion is the same as mine: VINDICATION