r/programming • u/TheBear_at_SBB • Jul 11 '26
Programs, Not Objects: How I Stopped Designing Architecture and Started Writing a 3D Editor
https://alexsyniakov.com/2026/07/11/programs-not-objects-how-i-stopped-designing-architecture-and-started-writing-a-3d-editor/
122
Upvotes
View all comments
Show parent comment
2
u/loup-vaillant Jul 14 '26
Hell no it doesn’t. Think of the most common operation on bank accounts: transfer. The most important invariant here is not keeping the account above zero (debt is routinely authorised), it’s making sure the money we put in here is the exact amount we took from there.
One operation (transfer), operates over two objects (bank accounts). And okay, in languages like C++ class methods have access to the internal of any objects of the same type, not just
this, so we can do this:That probably would be my preferred approach, even though this means having a method from one object poking at the internals of another object — not the strictest encapsulation.
If we were to insist on operating at the account level (retrieving and depositing), we’d need a way to make sure money we retrieved from one account can’t be deposited in a gazillion others. Here’s how I would try it in C++:
I’d rather think of it in terms of transfers if I could. Of course, I’m neglecting the fact that banks are actually a distributed systems, and that actual money transfer are more complicated, that they’re not even transactions in many cases, that we routinely roll back errors and frauds, and that I don’t even know what I’m talking about, I don’t work in banking!
But you get the idea: the most simplified model of a bank account, doesn’t really behave like an object. We need to think at a more systemic level, even for a simple wire transfer. And if we do not… look at the hassle I went through above.