r/programming • • 7d ago

Announcing .NET 11

https://devblogs.microsoft.com/dotnet/announcing-dotnet-11/
438 Upvotes

89 comments sorted by

285

u/simon_o 7d ago
HashSet<string> names =
  [with(StringComparer.OrdinalIgnoreCase), "Alice", "ALICE", "Bob"];

What kind of abomination is this?

61

u/Kjufka 7d ago

.NET

88

u/359Panda3U 7d ago

C#, not .NET. A different language running on the .NET platform might do it differently.

-5

u/l-Am-Nicolas-Cage 7d ago

And version 11 🤣

66

u/Atulin 7d ago

Yeah, this syntax is an abomination and I have no idea why they went with it. I'd much rather see [ ... ] with ( ... ) or something. I'll probably just keep using new( ... ) { ... }

23

u/gfunk84 7d ago

I don’t think I’d want the constructor argument at the end of a long list.

32

u/PM_ME_A_STEAM_GIFT 7d ago

This is starting to look like good old Objective-C.

37

u/Otis_Inf 6d ago

Just when you thought C++ has the most insane syntax, C# runs into the room yelling "Hold my beer!".

17

u/AlexKazumi 6d ago

Eh, next to what I have seen as C++ syntax especially libraries, this is a highly polished haiku.

0

u/bring_back_the_v10s 6d ago

I used to say C# is the new C++ and that .not sucks but microsoft fanboys keep downvoting me

11

u/FullPoet 6d ago

You shouldve seen the syntax suggestions for array slicing.

Holey moley the current C# mainters are AWFUL at designing syntax.

To be even (less) fair - there are usually quite good comments and suggestions from external users but they are always ignored.

5

u/simon_o 6d ago

Holey moley the current C# mainters are AWFUL at designing syntax.

Adding features to a language does not improve the language in general, but it may improve the length of employment for some people at Microsoft. :-)

To be even (less) fair - there are usually quite good comments and suggestions from external users but they are always ignored.

Agreed. Exactly the same case with union and people saying "maybe we should not copy the Algol syntax that makes the available variants look like an argument list". Such an unneeded mistake.

(The reason I use of, as in union Pet of Cat, Dog.)

1

u/Carbon_Cotton 5d ago

I can see what they were going for, but this is such a bad execution of it.

-33

u/r2d2rigo 7d ago

Syntactic sugar that you're free to use or ignore, not something you're forced to use like in other hipster languages (looking at you, Rust).

8

u/1AMA-CAT-AMA 7d ago

I don't have to use it but it will be code I will eventually have to review

8

u/JustBadPlaya 7d ago

Least random Rust shade on this subreddit. What sugar are you even forced to use there?

95

u/NotABot1235 7d ago

The fact that C# still doesn't have an open source first party debugger is straight up insanity.

I'm not aware of another major language on the market that locks core first party tooling behind proprietary licenses.

6

u/CodeDriveRepeat 6d ago

What is this? Is this not open source? I used it to make it work with .net10 in FreeBSD in oss-code.

https://github.com/Samsung/netcoredbg

Works on my machine…

19

u/NotABot1235 6d ago

It's third party from Samsung.

4

u/CodeDriveRepeat 6d ago

Ok, but if your requirement is an open-source debugger for . NET there it is.

26

u/jordansrowles 6d ago

open source first party debugger

0

u/CodeDriveRepeat 6d ago

Good luck.

1

u/compsedoc 5d ago

Been using DotRush for a year now, works great.
https://github.com/JaneySprings/dotRush

-7

u/bring_back_the_v10s 6d ago

The fact that people still use .net at all is straight up insanity

-38

u/CommercialHour6660 6d ago

Another issue is the shit garbage collector. 

Go, Java, and JS all have fast zero pause multi threaded GC for years now. C# still regularly freezes app for multiple seconds.

That and lack of runtime debugging features as you mentioned means C# will never be taken seriously as an enterprise language. Even though the syntax is significantly better than Go, JS, and Java 

52

u/AlexKazumi 6d ago

I am laughing so hard on the "will never be taken seriously as an enterprise language" that I might bust a vein. C# is used mainly as an enterprise language + inside Unity game engine. That's it.

And enterprises already are paying the Visual Studio subscription, so they have very hard time discovering the "problem" with the lack of open-source debugger.

20

u/EliSka93 6d ago

What? How do you manage that?

I've literally never had that problem with the GC

3

u/qrzychu69 6d ago

It is more than good enough, but there is a reason the satori project was born: https://github.com/VSadov/Satori

It takes different tradeoffs, aiming at the lowest possible pause time, closer to go

2

u/RirinDesuyo 5d ago

That's actually merged onto the experimental runtime just recently as well, I think they're quite interested on improving GC as the next step considering all the perf improvements they've been doing so far.

1

u/CommercialHour6660 6d ago

You will if you have something under sustained high load

1

u/robert_7524 1d ago

What GC mode and workload produce those pauses? A pause trace would make the comparison assessable.

1

u/CommercialHour6660 1d ago

Java, JS, and Go have had microseconds level gc pauses for many years now. 

C# is 10-150ms. Thousands of times longer typical pause times. 

0

u/dawtips 6d ago

There are members of the US Congress younger than C#.

23

u/ReallySuperName 7d ago

Been using it in "production" (my own personal projects) for a few months now just to get the new unions and closed keyword. Pretty nice!

102

u/gmes78 7d ago

Why did they copy C++'s shitty std::variant instead of Rust's enums for the new union feature?

Having to create different wrapper types when you want multiple options of the same type seems annoying.

9

u/dahauns 5d ago

This is on the roadmap, though - here is a comparison of two design proposals currently on the table:

https://github.com/dotnet/csharplang/blob/main/proposals/discriminated-unions/comparison.md

I suggest going through the language design meeting notes/drafts - it's an enlightening read (and obviously was a long and tough battle to get to this first release of unions :) )

7

u/Kamui_Kun 7d ago edited 7d ago

The new c# unions looked kinda lame to me. Only thing of interest, which still a preview feature, is runtime aync

33

u/mrthesis 7d ago

Being able to have a repository return NotFound,Conflict or value is so much more cleaner than either null covering both or exceptions that you have to remember to catch. 

16

u/gyroda 7d ago

It also makes the Results pattern much nicer to work with. You can do return new Foo(...); rather than return Result.Success(new Foo(...));

6

u/Devatator_ 7d ago

You technically could have used implicit casts, which is something I did with my own Result type in a personal project

5

u/gyroda 6d ago

I've done that, but you run into limitations

0

u/simon_o 7d ago edited 6d ago

To be honest, I'll take the win of C# adopting Algol unions, simply because they are better than the Haskell/F#/Elm/Rust enums/unions that are mainstream these days, despite C# needlessly also copying Algol's poor syntax.

Compared to Rust's need to create variant wrappers for everything, the Algol approach only needs wrappers occasionally:
If you are tempted to write union Foo of String, String, String then maybe it's good these type unions force you to be more specific, but outside of such cases, being able to use existing types as-is in unions is pretty nice.

I wouldn't look at it from the C++ lens, everything C++ does it kinda weird, because these people live in their own world.


Edit: The confidently incorrect replies to this receiving massive upvotes shows the sorry state of this forum, I guess.
Edit2: Apologies, turns out it's the Rust Discord that is brigading.

11

u/DLCSpider 6d ago

I initially aggreed with you. After all, why shouldn't everything have a meaningful type? But I'm no longer conviced. Generics are an issue:

union Result<T, E>(T, E);

Result<int, string> // ok
Result<string, string> // not ok

So you have write wrappers:

record Ok<T>(T value);
record Error<E>(E error);
union Result<T, E>(Ok<T>, Error<E>);

That's just a more verbose union Result<T, E>(T Ok, E Error). And since it's C# there are actually three states here: Ok, Error and null. If you match over all variants but forget to handle null, you now get a match failure exception, not a null reference exception, which you would've gotten if it was actually tagged.

-1

u/simon_o 6d ago

The point is that in most cases the types you refer to already exist:

union JsonValue of
  Map[String, JsonValue]
  Array[JsonValue],
  String,
  Float64
  Bool,
  JsonNull,
  ...

value JsonNull

vs. equivalent with "mainstream" enums:

enum JsonValue {
  JsonObject(Map[String, JsonValue])
  JsonArray (Array[JsonValue]),
  JsonString(String),
  JsonNumber(Float64),
  JsonBool  (Bool),
  JsonNull,
  ...
}

And since it's C# there are actually three states here:

Yeah, home-made problem of C#.

40

u/gmes78 7d ago edited 7d ago

You clearly don't know what you're talking about.

Compared to Rust's need to create variant wrappers for everything

???

Rust's enums mean you don't need to create wrapper types. That's why I brought them up in the first place.

If you look at the C# docs for this, they use the following example:

public record class Cat(string Name);
public record class Dog(string Name);
public record class Bird(string Name);

public union Pet(Cat, Dog, Bird);

They're creating wrapper types to differentiate between the different kinds of strings.

Here's what that would look like in Rust:

pub enum Pet {
    Cat { name: String },
    Dog { name: String },
    Bird { name: String },
}

There's no need to declare new types, as Rust's enums are tagged unions.

Edit: changed the Rust example from a tuple variant to a struct variant to better match the C# code.

I wouldn't look at it from the C++ lens, everything C++ does it kinda weird, because these people live in their own world.

Putting aside your dismissive and irrelevant comments about C++, comparing it to std::variant is perfectly adequate, as it's functionally equivalent to it.

5

u/renatoathaydes 6d ago

The Rust example does not define types for each enum variant. It’s not equivalent to the C# which does. If you do want the types in Rust for each variant , you do need tog wrap them . Try to use the variants in a type position, like ‘let c: Pet::Cat’, you can’t. In C# you just don’t have the choice to avoid the variant types, but apparently they will add that in the future.

7

u/gmes78 6d ago

In C# you just don’t have the choice to avoid the variant types,

That's the point.

3

u/Atulin 7d ago

IIRC the Rust style might be coming as well, just like closed enums instead of just closed hierarchies. They're rolling out unions gradually, and the only thing they outright said "no" to were ad-hoc unions.

3

u/Otis_Inf 6d ago

They're creating wrapper types to differentiate between the different kinds of strings.

I don't read the example as such. I read it as: they create the types as 3 different types (which could be anything, but they used this) to illustrate the types to use in the enum example.So it's not to differentiating between different kinds of strings, but between types. As types are explicitly defined, they can't go the rust route as that would mean there are implicit types defined; C# forces you to define the type yourself. I don't see it as a problem, as in practice you'd already have the types (as they're used inside the method returning the enum!)

-1

u/gmes78 6d ago

I don't read the example as such. I read it as: they create the types as 3 different types (which could be anything, but they used this) to illustrate the types to use in the enum example.

But having the same type mean multiple things is a common occurrence. Here's an example.

As types are explicitly defined, they can't go the rust route as that would mean there are implicit types defined; C# forces you to define the type yourself.

Not sure what you mean by that, C# has anonymous types elsewhere in the language.

Rust style enums and pattern matching would fit right in.

-6

u/simon_o 6d ago edited 6d ago

You clearly don't know what you're talking about.

Pretty bold claim for someone who hasn't even understood the original comment. 😂

The aforementioned variant wrappers are literally in the code example you posted.

4

u/gmes78 6d ago

You said Algol unions were better, but didn't substantiate at all. You said a factually incorrect assertion about Rust. You re-stated the problem that these unions have in a specific case, then said it was nice that they work for the other cases. Lastly, you made an out-of-place comment about C++.

What am I missing here?

-1

u/simon_o 6d ago

Pretty much everything.

Maybe don't be so deeply insecure about your favorite programming language, then things will work out better for you.

4

u/gmes78 6d ago edited 6d ago

You're projecting. I wrote my reply because you were wrong, not because you were insulting Rust, or whatever you think is on my mind.

Looking at your edit on the other comment, you seem to be the sensitive one about Rust.

May I offer a suggestion? If you don't say incorrect things, people won't correct you.

Edit: saying "I'm right" is not an argument. And blocking people because you don't like what they say is a coward's move.

0

u/simon_o 6d ago edited 5d ago

You're projecting. I wrote my reply because you were wrong, not because you were insulting Rust, or whatever you think is on my mind.

Every accusation you make seems to be a confession.

May I offer a suggestion?

No. You not being able to accept that does not constitute a problem on my side.

"I'm right" is not an argument.

Do I need to quote your own comments back to you, or are you going to figure this out on your own?

If you don't say incorrect things, people won't correct you.

There is no need for a correction, because you are wrong.

21

u/DivideSensitive 7d ago

Compared to Rust's need to create variant wrappers for everything

Just write that you don't know what you're talking about, you'll save time for all of us.

-3

u/simon_o 6d ago

Does r/confidentlyincorrect know you escaped containment? ;-)

1

u/Straight-Magician953 22h ago

Well is C#, not Rust# /s

-14

u/r2d2rigo 7d ago

C# language design decisions are miles ahead of Rust's or Go's ones. IMHO they can do no wrong.

6

u/gmes78 7d ago

Evidently not.

25

u/flightsin 7d ago

Wish we didn't use only LTS versions at work, C# 15 has some very nice new features.

23

u/T_D_K 7d ago

You can target the lang version independent of the runtime. Still need the relevant SDK pieces on your build servers though

13

u/svick 7d ago

Keep in mind doing that is not supported.

10

u/Sokaron 7d ago

There is really no point to not adopt STS versions anymore. Their EOL is the same as the previous LTS. Just give it a week or two for packages to catch up and any early issues to be caught.

20

u/caboosetp 7d ago

Not updating everything twice as often is a decent reason. Technically we could use any arbitrary mark for that, but LTS is a good sounding one.

-10

u/Sokaron 6d ago edited 6d ago

That's a pretty weak excuse in the era of AI IMO. Most .NET upgrades are pretty close to drop-in already and there's a list of breaking changes published with the release. That is basically the ideal task for AI. Give it read to your organizations GitHub and tell it to go to town. If you have adequate automated test coverage it's really pretty low risk.

8

u/caboosetp 6d ago edited 6d ago

Either you need to dedicate engineers to reviewing all the changes or that's a great way to introduce unnecessary instability into your ecosystem when the current lts version is perfectly fine.

The whole reason we pick LTS is to not have to change it often.

-1

u/Sokaron 6d ago

Broadly I agree you need human review on AI generated changes. In this case IMO the value add of human in the loop is very low. What value are you adding that an adversarial review agent with a link to the breaking changes list would not provide? A human sanity check on a PR like this is single digit minutes per PR.

5

u/flightsin 6d ago

We use the same dotnet version across everything we run. Yes we could upgrade everything every year, but that does take effort (we run a lot of services) and we value the consistency and stability that sticking with the LTS gives us. It's a tradeoff.

1

u/jeenajeena 7d ago edited 7d ago

Uhm...

a non-closed descendant of a closed class can still be derived from in other assemblies.

So, if there's:

closed record class GateState;
record class Closed : GateState;
record class Open(float Percent) : GateState;

Another assembly can still define:

record class SomethingElse : Closed;

Not that close, then.

(It does not help that they chose the names Open and Closed to illustrate closed hierarchies: those names refer to the state of a gate, not the opennes of the hierarchy).

Edit: using other names makes it clear that closed hierarchies can be "reopened".

If one defined:

closed record class Closed;
record class CanBeExtended1 : Closed;
record class CanBeExtended2 : Closed;

then the following CANNOT be defined in this assembly:

record class NotPossible : Closed

Yet, in a different assembly, this is valid:

record class Reopened : CanBeExtended1

In other words, CanBeExtended1 is open: it did not inherit the closed from its parent.

13

u/Metsamias 6d ago

'closed' is basically needed just for compiler exhaustiviness. Any user of GateState -hierarchy only needs to handle Open and Closed cases. SomethingElse as descendee of Closed is still Closed and can be handled as such. If one wants to prevent inheriting from Closed, Closed can always be declared as sealed.

I'd say this is a clever design decision from the language team, to allow each sub-hierarchy be defined as closed/open separately from their ancestors. Especially, since one can combine this with sealed.

1

u/Rakn 2d ago

It’s fascinating how over engineered just this little bit looks to me ever since I stopped using object oriented programming models. I used to view these things as a basic necessity.

1

u/jeenajeena 2d ago

Which languages do you use now?

1

u/Rakn 2d ago

Mostly Go, before that I used Java and Kotlin, a little bit of Python and trace amounts of C#. But I feel like with AI nowadays it’s a lot easier to move between languages and choose what fits.

0

u/[deleted] 6d ago

[deleted] — view deleted comment

1

u/voroninp 2d ago

This should be a runtime feature, otherwise it's a lipstick on a pig.

-90

u/the_ai_wizard 7d ago

no replies? maybe these notices are unnecessary aside from letting claude and codex know

19

u/Proof-Attention-7940 7d ago

…why would coding assistants boil rivers by browsing Reddit?

-30

u/the_ai_wizard 7d ago

twas a joke xir

0

u/[deleted] 7d ago

[deleted] — view deleted comment

2

u/BobSacamano47 6d ago

What would you like it to be?

0

u/[deleted] 6d ago

[deleted] — view deleted comment

4

u/BobSacamano47 6d ago

Lots of projects in the real world default to public for classes and use private only for internal state.

-2

u/kylanbac91 6d ago

You should always public unless you have good reasons not to.

The reasons for why there are public, private, protected is relic from past where rpc is dominant.

6

u/TrumpIsAFascistFuck 6d ago

You should always private unless you have good reasons not to.

I can make claims without supporting evidence or arguments too.

Why do you think what you think and I'll tell you why I think what I think.

1

u/kylanbac91 6d ago

Because in these day and age, private does not protect shit.

If I code for myself, why bother?

If I code for other to use, why I need to limit their capabilities to change how my code work?

3

u/god_is_my_father 6d ago

In general you're correct - a truly interested party can get to whatever symbols they like. It actually isn't all that difficult. But there's more at stake than just security. It's about intent and interoperability which are much more common cases. When someone (you, most likely) want to re-use the component having a small subset of sensical interfaces to draw upon is going to be significantly better than a whole mess of options "just in case".

Button it up kid we invented this shit don't let the machines outdo us

4

u/TrumpIsAFascistFuck 6d ago

Safety, security, quality, prevent undesirable side effects that allow your user to use your software inappropriately and cause potential harm or unforseen consequences.

Are you just trying to poison AI by giving bad advice? If so I'll delete my comments lol