- cross-posted to:
- [email protected]
- [email protected]
- cross-posted to:
- [email protected]
- [email protected]
Languages on the rise like Rust and Go are being quite vocal against inheritance and many engineers seem to agree. Why? And is it the fall of inheritance?
These “OOP is bad, here’s why” type of articles often can be simplified to the pattern of “here’s a terrible example of OOP, and here’s a very good functional solution of the same problem”.
On small scale, OOP just makes things way more complicated than it should be. On larger scale however, it works quite well, especially if you know where to break the rules.
Something doesn’t need inheritance? Don’t use it! I even use structs in D, which often speed up things by a lot, especially since they’re not ref by default.
One big issue I’ve seen to come up again and again is the programmer not knowing how to handle functions, that need to be called many times. By conventional OOP wisdom it’s done something like this:
class Foo { void doTheThing(Param p) { //doing the thing } } [...] for (int i ; i < timesToDo ; i++) { foo.doTheThing(param); }
However, we can move the iteration into the function of the class, so we will still have the power of class interchangeability:
class Foo { void doTheThing(int timesToDo, Param p) { for (int i ; i < timesToDo ; i++) { //doing the thing } } } [...] foo.doTheThing(timesToDo, param);
Inheritance can replace complex condition statements. The class
Foo
in my example could be a basis for a thing, that has its own internal state, which is pretty common in game development. However most people are not being taught game development, but instead things that assumed to make money, which include the hottest new trend. When I was beginning to learn programing in college, I was told that we can say goodbye to .exe files, to say goodbye to installing programs to your PC, because everything is going to be web based, thanks to… Flash??? And Java applets??? Funny, it turned out to be JavaScript to be the winner, and now we have applications on our computers that are just glorified Chromium browsers running what are essentially interactive web pages, which got so widespread there are now coders not only afraid of all pointers, but also type declarations.In my honest opinion:
goto
statements, it was revolutionary. However, we might never replicate its impact yet again in our lifetime. Maybe it’ll never be replicated ever again. People are already failing to find the next iPhone, which are just nicer looking PDAs.const
everywhere. And so on, and so on, and so on.Yeah. I read a lot less about large FP codebases than about large OOP codebases. Wonder why. /s
Some things just can’t be properly seen and evaluated in a tiny made-up example that fits in a blog post.
Plus, you have large teams with devs of different skills. Will they all be able to use the wonderful functional idioms that solve all problems and make everything great? Looks like more devs are able to use OOP, warts and all, to create some workable projects. Even if not supremely elegant.