Live data from Hacker News

What's new in C# 12: overview

pvs-studio.com

91–100 of 100 posts

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

#91
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…

We've recently started writing our new stuff in .Net, and I last used it back in .Net 1.1 days. I've been super productive from the first day of returning.

Like you say Visual Studio helps a lot with suggesting improvements, and of course all my old ways are still valid.

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

#92

Earlier quoted context omitted.

The real problem is you are testing the class behaves like the class, but not the business-driven requirements. Therefore refactoring becomes fearful since detecting bugs is no longer the job of tests.

A business model can be described in code as an integration test. Wouldn’t an integration test work in that case?

Yes, depending on what you mean by integration test.

It is nuanced subject.

But say you have class A,B,C,D with mocked dependencies E,F,G,H.

There could be bugs in how A interacts with E and F that are hidden even though you have tests for A,B,C,D integrated and even unit tests on E too.

In addition, if someone comes along and refactors A,B,C,D into A',B',C',D' that have different dependencies ("Hey we are moving to microservices!") then the new integration test is different. You change test and code at the same time.

This is a problem because confidence comes from having a stable test, then changing the code and getting the green circles.

The solution (I think) is to make sure you are mocking at the level of well established boundaries. For example mock PostgreSQL. Or mock your ORM if there is a decent mock, with an in-memory version.

Then you can test end-to-end scenarios. Add a TODO, add another TODO, assert that getTodos() returns 2 results, and so on.

Instead of assert getTodos() returns 2 results when the ITodoService.getTodos() returns 2 results, and the outer getTodos just defers to it.

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

#93
post #14

I love that Java and C# (not sure about VB.NET and F# in the .NET ecosystem) are continuing to get handy language features instead of collecting dust. The array syntax stuff is a nice win. Having other languages be the guinea pigs for language features is a good way to go.

They seem to have picked most of the low hanging fruit though. Most of this is nice to have but not earth shattering. The only feature I've been hoping for is abstract data types. I'm not sure how they could make them work in .Net though. Presumably F# has crossed that hurdle.

I want algebraic data types, again not sure if it's doable but they already have the pattern matching to support it.

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

#94
post #66

Earlier quoted context omitted.

Discriminated Unions will make working with Result easier as would provide exhaustive checking. DUs are being designed: https://github.com/dotnet/csharplang/issues/113

Fantastic. I note it's indeed being designed since 2017 so it's probably not as easy as I would hope. The design seems to not have progressed beyond discussion at all in 6 years.

I suspect a lot of the pattern matching stuff was built in order to support these. Sum types are a feature I'm really excited for.

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

#95

Earlier quoted context omitted.

They seem to have picked most of the low hanging fruit though. Most of this is nice to have but not earth shattering. The only feature I've been hoping for is abstract data types. I'm not sure how they could make them work in .Net though. Presumably F# has crossed that hurdle.

I want algebraic data types, again not sure if it's doable but they already have the pattern matching to support it.

With sealed classes and explicit inheritance you have it in Java now

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

#96
post #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 lea…

Personally, I'm still using var for most locals, but target-typed new for field and property initializers. Not every feature had to be used everywhere.

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

#97

Earlier quoted context omitted.

A business model can be described in code as an integration test. Wouldn’t an integration test work in that case?

Yes, depending on what you mean by integration test. It is nuanced subject. But say you have class A,B,C,D with mocked dependencies E,F,G,H. There could be bugs in how A interacts with E and F that are hidden even though you have tests for A,B,C,D integrated and even unit tests on E too. In addition, if someone comes along and refactors A,B,C,D into A',B',C',D' that have different dependencies ("Hey we are moving to…

If the parent comment is also saying "If a test describes a business requirement rather than a class and method, then it must be an integration test"

Then I think that parent is wrong, or rather that "it depends on what you mean by integration test" an further, this definition of "integration test" is an extremely unhelpful one that I do not advise using. And it better fits what was originally intended as "unit test". The name "unit" is not a synonym for class or method, it is your choice what the "unit" is, and a lot of the time it is best done as a small chunk of business requirement.

mocking at the level of well established boundaries such as databases and http services, is all that's needed.

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

#98

Earlier quoted context omitted.

I didn't write that all additions to C# since 1.0 are useless. We have generics since .NET 2 (2005 IIRC) and at the time, the lang improvements had a reason to exist (framework support in some cases). At the time it was a nice thing to add, if you ask me. For me, the next big thing, if you ask, was LINQ. A few years later, I feel it's not the case with recent additions. But my comment is very subjective, of course. A…

Well, is LINQ really a lang. feature? Extension methods are lang feature, LINQ is implemented with ext. Methods. You can argue that there is LINQ Query syntax instead of method chaining, but almost nobody is using this except for some specific cases (let keyword)

LINQ to objects yes, but LINQ to SQL is a different beast where the C# code is translated to SQL. Expression trees are very much a language feature, I guess.

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

#99
post #98

Earlier quoted context omitted.

Well, is LINQ really a lang. feature? Extension methods are lang feature, LINQ is implemented with ext. Methods. You can argue that there is LINQ Query syntax instead of method chaining, but almost nobody is using this except for some specific cases (let keyword)

LINQ to objects yes, but LINQ to SQL is a different beast where the C# code is translated to SQL. Expression trees are very much a language feature, I guess.

Fair, expression trees are really good

But I thought they are implemented at library level, but now Im not sure

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

#100
post #52

As a dev that uses tuples to standardize returns. I welcome the new using feature.

May I know how would this help ? They don't have generic support no ? You create tuple type for every method ?

My business classes have a lot of methods that return tuples that look like this.

  (bool HasFailed, string Status)
Also yes tuples do support generics.
Post reply on HN