2 ms·
To me, the big difference between a struct and an object is when data has constraints. Let's say I have a rotation matrix. That means that the squares of all
by AnimalMuppet 3y ago
To me, the big difference between a struct and an object is when data has constraints.
Let's say I have a rotation matrix. That means that the squares of all the entries in any one row or column add up to 1. If I have such a structure, and I find that it has rows that no longer add up to 1, well, what function messed it up? I have no idea. And if I have a million lines of code, that gives me a lot of places I have to look.
But with an object, if I made that data private, only a member function can have messed up. I may still have a thousand lines I have to look at, but that's a lot less than a million. For larger code (tens of thousands of lines and larger), I consider access control to be essential, just to limit the size of the code that could possibly be at fault.
Back in the day, I spent a lot of time playing "who messed up the structure?" in structure-and-function code...
- ReleaseCandidat 3y ago> But with an object, if I made that data private Being able to make a field of a record private does have nothing to do with OOP, even in C you can hide a struct's fields.
- deleted 3y ago[deleted]