What’s coming in C# 12? Devs debate whether it’s too much or not enough

What’s coming in C# 12? Devs debate whether it’s too much or not enough

Microsoft’s C# lead designer Mads Torgersen, along with principal software engineer Dustin Campbell, presented a look at what is coming in C# 12 and beyond at the company’s Build event last week.

C# is the primary language of the company’s .NET platform and the language is updated with it annually. “Novemberish time when .NET always ships,” said Torgersen.

There are always new features, though according to Principal Program Manager Kathleen Dollard, writing on the same subject last month, “our design process has changed due to shorter scheduled release cycles. This allows us to think of evolving features over many releases, rather than trying to bundle a huge issue together. There is no aspect of C# that I would consider “finished” and I think this leads to a gentler evolution.”

Torgersen and Campbell presented several new features expected in C# 12.

Primary constructors, already implemented for record types, will be added to non-record classes and structs. Primary constructors will let developers add parameters to the class declaration, the values of which can then be used to initialize properties. However, unlike with records, there will be no automatic creation of properties. “It’s not so cool for everything to show up as a public property when you want to use classic encapsulation and so on,” said Torgersen. Primary constructors were originally planned for C# 6, he added, but “we didn’t do primary constrctors in C# 6 because it was that, or interpolated strings.”

Another key feature is “using” aliases for any type, which lets developers create type names that are meaningful to an application, that are actually aliases to generic types. “You can create semantic aliases for tuple types, array types, pointer types, or other unsafe types,” the docs explain.

There is more coming, and the duo also spoke of future plans for enhancements to extension methods, for example, the hope being for a “new breakthrough in software composition.” Then again, “We might have to do things in the runtime… this might come to nothing” Torgersen said.

The subject of C# improvements is a touchy one among developers though. “Please put some attention towards completing existing language features that were cut from previous releases,” complained one developer, referencing problems with default interface implementations referenced here and outstanding since 2019.

Another common complaint is that C# risks becoming too complex, or may already be. Regarding primary constructors, one said that “I fear this feature will further complicate the language. I don’t want C# to end up being as complicated as C++ when it comes to finding out where a member variable is initialized (if ever).”

“What a nice, simple and powerful language it was few years ago, then you added some nice and useful syntactic sugar. And then somebody showed up and invented dozens ways of object initialization. Stop polluting C#. Stop this madness,” said another.

Torgersen and his colleagues have the tough job of paying attention to these calls for simplicity on the one hand, while also dealing with a host of feature requests on the other.