I haven't yet seen a usage of a struct where a tuple couldn't have been used, I haven't seen a usage of struct where a record wouldn't be the same (as far as I can remember), and I would like to see an example of struct usage where a tuple, record, or class wouldn't be better.
I would posit that structs are a remnant of C, of a time when returning multiple values were hard but needed, and that using them for more than transporting immutable values is breaking the design philosophy of OOP in general and structs in particular.
Talking only about my experience: a pretty obvious example taken directly from .NET is vectors and a lot of things connected to maths, maybe besides matrices, because they are simply too big to be structs (though they are structs in Unity for example). In games engines and graphic programming, there is much usage for structs - they don't need GC, they are faster and they work better with value-type semantic. Ok, you could perhaps use a tuple as a vector, but tuples are very limited - no methods, no operators overloading, no control over pretty much anything. Records and classes are reference types, so you have to deal with GC overhead, and honestly, that should be enough not to use them.Additionally, structs are useful and sometimes basically necessary for interop.In C# they are also the only really immutable type, though records are close now.Also, in my opinion not everything has to adhere to a design philosophy of OOP, especially when C# is a multi-paradigm language.
1
u/OrganicBid Dec 20 '20
I haven't yet seen a usage of a struct where a tuple couldn't have been used, I haven't seen a usage of struct where a record wouldn't be the same (as far as I can remember), and I would like to see an example of struct usage where a tuple, record, or class wouldn't be better.
I would posit that structs are a remnant of C, of a time when returning multiple values were hard but needed, and that using them for more than transporting immutable values is breaking the design philosophy of OOP in general and structs in particular.