4 ms·
In reality there is a lot of overlap between structs and classes that the intent seems to be a bit lost on modern devs. They were intended (going back at least
by bigtunacan 4y ago
In reality there is a lot of overlap between structs and classes that the intent seems to be a bit lost on modern devs.
They were intended (going back at least to C++) to convey different things. A struct is a light abstraction of related things. So instead of having int x, int y everywhere you have Struct Point.
A class has responsibilities, implies state, implies interfaces.
Given the signaling that structs send they should be value objects and as such the original Ruby struct is a bad implementation. The Data object is basically a concession of this with an understanding that changing struct would break "all the things" that already use struct.
- vidarh 4y agoIn C++ a struct from the start was a class with default public visibility. You can define member function on them.
- bigtunacan 4y agoYes I'm aware. You can define methods/functions on most (if not all implementations of struct); Ruby's is no exception to this. The parent indicated they didn't understand why both struct/class exist because there is so much overlap. The primary reason is to signal intent. This has largely been lost as the masses just use classes for everything or they use simple data types like hashes.