3 ms·
> Proper value types (Even .NET is only catching up since C# 7.0) In C# structs are value types, and they've been with .Net since the beginning IIRC. I assume
by Merad 6y ago
> Proper value types (Even .NET is only catching up since C# 7.0)
In C# structs are value types, and they've been with .Net since the beginning IIRC. I assume maybe you're referring to System.ValueTuple? It was added in C# 7 and allowed tuples to be value types along with significantly better syntax for working with them.
- hackerfromthefu 6y agoYou are correct Struct value types on the stack was a 1.0 feature in 2002.
- pjmlp 6y agoIndeed, that wasn't what I was referring to. There is so much more for value type programming, see sibling comment.
- pjmlp 6y agoI was referring to: - proper memory slices - ability to do stackalloc in safe code - readonly structs - generics for blittable types - zero allocation pipelines - using without IDispose for structs without implicit boxing - return scope for zero copy struct parameters - native function pointers - static lambdas
- MaXtreeM 6y agoIf this is what you mean by "proper value types" then I think that the "value type" term is bloated. For me value types mean value semantics and what you describe are mostly optimizations. I like the point of Eric Lippert, that value types is not the same as "should live on stack" as a lot of people think. I would agree that things like > - using without IDispose for structs without implicit boxing and > - generics for blittable types would make value types more "proper" in the C# language.
- pjmlp 6y agoValue types without the optimizations I listed is what keeps people writing C++ instead of doing everything in .NET proper. Just like C and C++ offer similar optimizations to avoid writing the tons of Assembly that was so common up to the mid-90's. So yes, optimizations are definitly part of proper value types.
- whoisthemachine 6y agoYou're right - but maybe he's referring to record types, which are reference types that compare by value? [0] [0] https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/exploration/records https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/exp...