Live data from Hacker News

What's new in C# 12: overview

pvs-studio.com

41–50 of 100 posts

Re: What's new in C# 12: overview

#42
post #38

Code interception strikes me as just crude and poorly conceived? Given how hard it is to remove features from a language, why introduce things like this? 20 years from now people will have to deal with codebases that use InterceptsLocation decorators and for what? I get why InterceptsLocation can be useful, but why not make a more generic version that doesn't work with magic line and character offsets? Something as i…

Well, this features is designed to be used by source generators and not humans.

So as it's intended for being used inside the compilation process, i don't think this is too valid of a concern.

Re: What's new in C# 12: overview

#43
post #11
post #3

>finally, we can stop creating an interface for every class just to mock it in tests Is there more information available about this? Would be great to achieve this natively without requiring Fody and friends.

I've HATED it when people do this, but everyone is convinced it's best practice.

I hate it as well, and seldom do it on my own projects.

At work, I have better things to do than waste time on this for PR, so I create those interfaces, thankfully there are VS tools to create them automatically.

Re: What's new in C# 12: overview

#44
post #35
post #12

Not sure if I like primary constructors. TBH, the following feature of Dart that I like: class Point { public Point(this x, this y); int x; int y } Everything else seems like small quality of life improvements. And still patiently waiting for the following to be legal: int result = some_variable switch { a => callAFunctionReturningVoid(); 1, b => 2, };

> int result = some_variable switch { a => callAFunctionReturningVoid(); 1, b => 2, }; What does it even mean? Multi-statement lambdas without return statement, I get it, but what is the return value? And returning a void to int? How is it all supposed to work? What the trailing comma means? Inconsistent way of dealing with things that may confuse developers just results in that proposal resisted.

It is not a lambda but a switch expression. The tricky bits here are separating a call and the returned expression with ;. The trailing comma is just sugar to allow for another case

Re: What's new in C# 12: overview

#45
post #31

Just a reminder that in the C# world you don't really have to care about new language features. Visual Studio, ReSharper, and Rider (supports MacOS/Linux) will suggest useful new language features as a one-shortcut refactoring. A C# developers who went into coma in 2012 after learning about async/await and ASP.NET MVC can be awakened today and be instantly productive. Although he might go into coma again if he finds…

Or that the beloved frameworks they use in-house only work in .NET Framework, or even if ported to .NET Core they are still Windows only, because they are wrappers around COM.

Re: What's new in C# 12: overview

#46
post #3

>finally, we can stop creating an interface for every class just to mock it in tests Is there more information available about this? Would be great to achieve this natively without requiring Fody and friends.

It's more for DI than tests, really, right? Still, I have very rarely found it practical.

Re: What's new in C# 12: overview

#47
post #38

Code interception strikes me as just crude and poorly conceived? Given how hard it is to remove features from a language, why introduce things like this? 20 years from now people will have to deal with codebases that use InterceptsLocation decorators and for what? I get why InterceptsLocation can be useful, but why not make a more generic version that doesn't work with magic line and character offsets? Something as i…

Well, this features is designed to be used by source generators and not humans. So as it's intended for being used inside the compilation process, i don't think this is too valid of a concern.

Source code generators are used because the language itself is not expressive enough. Maybe fix that instead.

Re: What's new in C# 12: overview

#48
post #38

Code interception strikes me as just crude and poorly conceived? Given how hard it is to remove features from a language, why introduce things like this? 20 years from now people will have to deal with codebases that use InterceptsLocation decorators and for what? I get why InterceptsLocation can be useful, but why not make a more generic version that doesn't work with magic line and character offsets? Something as i…

Well, this features is designed to be used by source generators and not humans. So as it's intended for being used inside the compilation process, i don't think this is too valid of a concern.

That's good to know. I wonder if VS and VS Code are set to at least produce warnings when the feature is used in human generated code. Any feature can be abused, will be abused. At least with warnings by default the programmer can know this isn't a desired use case and then decide if their particular need is a worthwhile exception.

Re: What's new in C# 12: overview

#49
unions, c3 and struct inheritance, private constructors in non static class, sealed hierarchies of records has no warnings in switch, operators and ref parametes are integrated into type system. than i may return back.

Re: What's new in C# 12: overview

#50
post #3

>finally, we can stop creating an interface for every class just to mock it in tests Is there more information available about this? Would be great to achieve this natively without requiring Fody and friends.

It's more for DI than tests, really, right? Still, I have very rarely found it practical.

They're not required for MS's dependency injection, not sure about other libraries. 95% of the interfaces I've ever seen used for DI only have one implementation, and that 5% is generous. This makes maintaining the class and the interface tedious.

The reason this is so common is probably because code examples (including MS) often have it, so it gets followed the first time and repeated.

Post reply on HN