Extension Types Delay?
It seems the language design team has decided to delay the implicit and explicit extension type (formally extentions and roles) feature for C# 12.
Personally the feature I was the most hyped for.
Are anyone aware of an official reason as to why it was delayed?
Google seems to be letting me down here.
15 Replies
they haven't finished designing/implementing the feature
$languagefeaturestatus has a list of features in progress
You can see the features the team is currently working on here: https://github.com/dotnet/roslyn/blob/main/docs/Language%20Feature%20Status.md
Fair enough.
For primary constructors it seems they decided not to add this part yet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-12.0/primary-constructors.md#combined-parameter-and-member-declarations
Primary constructors almost seem kinda pointless without it.
I'm aware records do this implicitly, but because records not being mutable has spolied the records feature for me from the start.
GitHub
csharplang/proposals/csharp-12.0/primary-constructors.md at main · ...
The official repo for the design of the C# programming language - dotnet/csharplang
Primary constructors almost seem kinda pointless without it.you can still use the ctor params as implicit fields, which will be quite useful for DI or assign them to props if that works better for you, still shorter
It seems the language design team has decided to delay the implicit and explicit extension type (formally extentions and roles) feature for C# 12.There was never a hope in heck that it would be actually done for C# 12. At best, it would have been partially in preview
I'm aware records do this implicitly, but because records not being mutable has spolied the records feature for me from the start.Not sure what you mean by this, but if records were mutable by default, the feature would have been a shotgun waiting to go off in every developer's face
is it still planned to drop in some sort of preview before C# 13?
or was that another feature?
Hopefully
You mean I can declare the properties manually with the primary constrictor argument used as the initiator like they show in the examples? Sure that is slightly faster but as I said the implicit declaration would make it even faster though
You'll never implicitly get properties from non-record primary ctor declarations
Now, maybe adding
public
or something like that to a pc parameter will be a shorthand
We're a bit split on whether that's even something we want right nowProperties of records can’t be changed outside of the object initializer
I’m aware this is becuase you are meant to use the ‘with’ keyword to clone the instance with the specified mutation but that means unnecessary allocations when the benefits of such a model is not needed.
I know this is what developers wanted with the feature. I’m just saying it usually isn’t what I want.
Which is why I would like automatic field generation for primary constructors to fill that need given the only alternative is doing a bunch of boilerplate your self or use record structs which are mutable I believe or at least the with keyword is less expensive with no allocations
Also I would like to declarify something I said above, when I said implicit field generation I meant when adding a accessor keyword like what have been discussed aka explicit. I know actual implicit generation like records is certainly not what the feature is about
Yeah, the problem with mutability in record classes is that they have value-equality
Yeah, on that subject btw, is there a reason why the EqualityComparer system is used in the auto generated equality methods for primitive types. Don’t that require a virtual call compared to just emitting == ?
Just something I have been wondering about for a while.
It of course creates a semilare outcome, but a virtual call just seems wasteful since it would hardly be good practice to overwrite the equality comparer for primitive types
Because we don't special case them
It's also a) likely to be devirtualized by the JIT, and b) not really a dominating factor in the performance
Alright fair enough