by spoiler · 1w ago · 0 comments
Most of the complexity I've seen in most programs I worked with so far was avoidable complexity, caused by under- and over-engineering. Mostly the latter.
If I had to identify the biggest culprit, that would be the OOP cult: all these organisation "principles" (not just SOLID) that have little basis in reality, and ultimately causes programs to be up to several times bigger, and up to several orders of magnitude slower, than the reasonable thing that just does the job.
The slower part is mostly because we forgot the laws of physics, ironically: the speed of light that ultimately drives the cache hierarchy for instance. That stuff is so fundamental by the way that even we humans have similar limitations with our working memory. The reason we split our source code in manageable, relatively isolated chunks, is very similar to the reason CPUs work faster when memory locality is good.
This parallel by the way may explain in part why simpler programs tends to run faster.
And, to be clear, I don’t think OOP is the best tool for that.
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 small code bases this doesn’t matter. In multi-million like code bases, it does. Now you have to care about type gymnastics, interfaces, design patterns, factories, whatever the hell. Because otherwise everything is too everywhere, and small changes have cascading effects. Maybe that doesn’t sound too bad, but where it gets bad is when you can’t see those effects. Now every change is risky.
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.
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.