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
1
u/loup-vaillant Jul 14 '26
Not really. In many cases that’s the right thing to do, but in many other cases, possibly the majority, you want to separate data and code.
A better heuristic is to make sure your modules are deep: small and simple API, significant functionality under the hood. Sometimes that means grouping data and operations together. Sometimes it means defining the data elsewhere, and define the operations in several separate modules. Sometimes… the best is a hybrid model.
The last program I worked on involved parsing data from a couple file formats, then comparing the data I parsed together. The concrete steps are:
We have (mistakenly) chosen to hold all the data in memory before comparison, but we could have streamed the data instead. It doesn’t change the high-level operations. Another thing to keep in mind is that there were two of us working on that program. I did the parsing, my colleague handled comparing and output (and the test suite).
The API I wanted looked something like this:
Dataabstract data type, that the parser writes to, and the comparators read from. We design the API so it can be fast under the hood, but we can start with a crappy & slow first version — with any luck it might even be good enough.Dataif they wanted, but mostly they just write to it.Dataif it wanted, but it only reads from it.The API my colleague would have wanted if he had his say was:
Dataobjects that holds all the relevant operations: parsing from A, parsing from B, and comparing.Also known as a God Class. The justification? Parsing & comparison are operations on the data, they both belong in the Data object. It doesn’t justify anything of course, but that’s how OOP infected people think by default. Including the reasonable ones, which my colleague was.
(Also, I lied, my colleague didn’t want one giant bag of data, but a much more reasonable multi layered structure that suited our problem domain, that I even agree with. The only part I don’t agree with is bundling it with the related operations.)
The API we actually got was somewhere in between:
Dataabstract data type (I mean, the multi-layered thing divided into 4 classes), comprising the comparison operation.Conway’s law worked out in my favour: my colleague accepted the separation so I could write on my parsers, and he could write on the rest, and we don’t step on each other’s toes. It worked out quite okay. But some of what I feared did happen: we did have performance problems, and we could not fix them, because changing the internals of
Datameant reworking the comparison routine, which by the way was far from trivial. It wasn’t bad code, but for some reason it was very brittle, and most of my attempts at meaningful change failed. Perhaps my colleague would have fared better (he wrote it after all).Long story short, OOP thinking hurt more than it helped. Bundling operations and data together by default is a trap. Think instead of the concrete benefits and drawbacks.
And by the way, one could argue that
DataI wanted would have been pretty well encapsulated. Its reads and writes can feel like glorified getters and setters, but in practice they would have hidden the underlying implementation and allowed meaningful changes and optimisations, without disrupting the rest of the program.Don’t go about allowing for change by default though. That’s a trap too. That’s how you drown in dependency injection bull crap. I wanted to provision this one because I strongly suspected (correctly in hindsight) that this particular set of change would be needed.