3 ms·
When writing Python, I usually try to follow this item from the C++ Core Guidelines (replace "struct" with "dataclass"): > C.2: Use class if the class has an i
by nemetroid 6y ago
When writing Python, I usually try to follow this item from the C++ Core Guidelines (replace "struct" with "dataclass"):
> C.2: Use class if the class has an invariant; use struct if the data members can vary independently
> An invariant is a logical condition for the members of an object that a constructor must establish for the public member functions to assume. After the invariant is established (typically by a constructor) every member function can be called for the object. An invariant can be stated informally (e.g., in a comment) or more formally using Expects.
> If all data members can vary independently of each other, no invariant is possible.
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-struct https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines...