Hacker News new | ask | show | jobs
by loup-vaillant 1 day ago
> The main purpose of OOP is not actually to make code simpler or easier to understand, it’s to make code more maintainable.

And it failed in my opinion. It's not just "not the best tool", it made things slightly worse in practice than plain procedural programming (with basic modules such as C's compilation units).

> But, the idea of all these abstractions and de-coupling and dependency injection and whatnot is to make it easier to add code with less risk.

In my experience, those things make this harder and riskier in practice. One reason being the sheer amount of boilerplate. The other being the wrong kind of abstraction, decided too soon.

I've had over 20 years to think about this and try things out. At this point I'm fairly sure that OOP was by and large a mistake. Not trying it I mean. Progress requires much trial and error. The real mistake was persisting more than 2 decades longer than we should have.

1 comments

I largely agree that OOP was a mistake, but I've also worked on very complex procedural code, and it's worse. The abstractions do help.

Even something as simple as "this function isn't public so I can safely change it's signature without breaking consumers outside of the class" has HUGE benefits. In something like C, that's not possible. If I change a signature, I have no idea how much stuff I just broke, how large the blast radius is. So, it's more risky.

It's a similar thing with interfaces or abstract classes. I need some new functionality. Adding it without an interface is very risky, because I can break a ton of consumers. Or, I can't reuse existing code that we know works, because it's too concrete.

Like, maybe I have a function that converts a file to an excel workbook. I built it to read off of disk. But now, I need it to sometimes read from S3. Without interfaces this is very hard. I have to program in new logic to the excel workbook generation function, and I can break it.

But if the file reader was an interface, I could just make a new implementation for network attached files. Now, I can re-use all the logic of the excel workbook function and ensure I didn't break it.

Yes, there is a problem with poor abstractions. But abstractions, indirection, and de-coupling as a whole is the only reason large codebases can exist. When everything is too everywhere, then changes become too risky, so we just don't make them, and software rots.