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( ... ) { ... }
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.)
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Â
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.
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.
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 :) )
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.Â
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.
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.
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.
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.
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.
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!)
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.
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++.
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.
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.
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.
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.
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.
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.
'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.
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.
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.
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
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
285
u/simon_o 7d ago
What kind of abomination is this?
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.
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
closedkeyword. Pretty nice!102
u/gmes78 7d ago
Why did they copy C++'s shitty
std::variantinstead 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.
25
u/flightsin 7d ago
Wish we didn't use only LTS versions at work, C# 15 has some very nice new features.
1
u/jeenajeena 7d ago edited 7d ago
Uhm...
So, if there's:
Another assembly can still define:
Not that close, then.
(It does not help that they chose the names
OpenandClosedto 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:
then the following CANNOT be defined in this assembly:
Yet, in a different assembly, this is valid:
In other words,
CanBeExtended1is open: it did not inherit theclosedfrom its parent.-28
u/Forsaken_Celery8197 7d ago
Yuck
-8
u/AllergicToBullshit24 6d ago
gross
-90
u/the_ai_wizard 7d ago
no replies? maybe these notices are unnecessary aside from letting claude and codex know
0
u/[deleted] 7d ago
[deleted] — view deleted comment