Live data from Hacker News

What's new in C# 12: overview

pvs-studio.com

1–10 of 100 posts

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

#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.

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

#5
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.

Some would argue that creating interface for every class and using too much mocks than actually needed is baad.

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

#6
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.

Some would argue that creating interface for every class and using too much mocks than actually needed is baad.

Yep. The issue with tests that are heavy on interfaces and mocks is that they are "too close" to the code - if refactoring is changing code while tests stay green, how can you refactor when any change to any method breaks a test?

Swapping out interfaces to code-gened interceptors and keeping everything else the same, doesn't look like it would improve this underlying issue at all.

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

#7

Primary Constructors and Collection Syntax seem good. I think with target typed new and this new collection syntax I probably won't use var anymore.

The old collection initialisation syntax has always felt clunky compared to many other languages, especially with more complex Dictionary types. At the same time it feels funny going back to having the type defined first since many have spent years converting explicit 'Type foo...' into 'var foo...' because the linter suggested it. Then again, perhaps this is one step towards more type inference and being able to leave out the type in more places

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

#8
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.

Nice to see this so I can convince a fellow tech lead that the reason that we’re creating interfaces for every class has nothing to do with future extensibility and has everything to do with maintaining unit tests and that even official MS sources think that’s the case (he doesn’t believe in anything until an MS based source says it).

And Unit tests make especially little sense in the specific service I’ve been talking about because all the logic is in the Stored Procs it calls. The service itself simply forwards that data.

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

#9

>InterceptsLocation("Program.cs", line: 3, character: 7)] That line and character worries me But since this is generated then maybe it is fine?

From the article: The new syntax is appropriate for source generators, so don't be surprised by its clunkiness
Post reply on HN