Live data from Hacker News

.NET (OK, C#) finally gets union types

andrewlock.net

31–40 of 300 posts

Re: .NET (OK, C#) finally gets union types

#31
I love C# and in every iteration we're getting more and more features to get C-like performance in a lot of scenarios. C# does it really well because if your problem isn't performance/memory-constrained, you can ignore these features and fallback on the language's natural ease of use.

Re: .NET (OK, C#) finally gets union types

#32
post #23

I mean yes, but also: uh-oh. I'm looking forward to reading some code that is even more confusing than the code I'm already reading. Not entirely convinced that I see the usecase that makes up for the potential madness.

Discriminated union types are a really fundamental building block of a type system. It's a sad state of matters that many mainstream languages don't have them.

ok, so what problems do they help me solve that I can't already solve? Is it just that we can make code more concise or am I missing a trick somewhere?

Re: .NET (OK, C#) finally gets union types

#33
post #10

Earlier quoted context omitted.

It’s huge in the game dev world, with Unity and Godot. .net also had a reasonable community on mobile for a while thanks to Xamarin, but I cannot imagine that many people using it for new mobile projects in 2026 (outside of game dev I mean). It’s a very decent language (I mean C#) and runtime, I wish it had more market share in the startup world.

An enterprise shop I co-op'd at was porting one of their apps from Xamarin to MAUI when I worked there, but certainly it doesn't have much mindshare (if any) amongst SE undergrads at my university.

Someone I know who works with .net says that there is still no replacement for full Visual Studio for development, which is Windows only.

Re: .NET (OK, C#) finally gets union types

#34

Earlier quoted context omitted.

Unions are simpler than subclasses and more powerful than enums, so the use cases are plentiful. This should reduce the proliferation of verbose class hierarchies in C#. Algebraic data types (i.e. records and unions) can usually express domain models much more succinctly than traditional OO.

> so the use cases are plentiful such as? > This should reduce the proliferation of verbose class hierarchies in C# So just as an alternative for class hierarchies? I mean good people already balance that by having a preference for composition.

Simple example:

   type Expr =
       | Primitive of int
       | Addition of (Expr * Expr)
       | Subtraction of (Expr * Expr)
       | Negation of Expr

Re: .NET (OK, C#) finally gets union types

#37

Earlier quoted context omitted.

> so the use cases are plentiful such as? > This should reduce the proliferation of verbose class hierarchies in C# So just as an alternative for class hierarchies? I mean good people already balance that by having a preference for composition.

Simple example: type Expr = | Primitive of int | Addition of (Expr * Expr) | Subtraction of (Expr * Expr) | Negation of Expr

Isn't that just Func ?

Re: .NET (OK, C#) finally gets union types

#38
post #2

F# leads the way and C# slowly catches up, as always. Yet for some reason, C# still gets all the mindshare.

Haskell, OCaml, Erlang lead the way and Rust, Zig and Go get all the mindshare. I feel like its a common pattern for more experimental languages to pioneer features and other languages to copy the features and bring them to a C style syntax that the majority of devs are familiar with.

Rust and Zig brought new ideas for memory management that Haskell, OCaml, Erlang sidestep having garbage control. its honestly amazing to me that they managed to get the adoption they have while being so innovative. I say this as a fulltime elixir dev.

Re: .NET (OK, C#) finally gets union types

#39

I mean yes, but also: uh-oh. I'm looking forward to reading some code that is even more confusing than the code I'm already reading. Not entirely convinced that I see the usecase that makes up for the potential madness.

[flagged]

I love discriminated unions.

The problem with C# is that it’s so overloaded with features.

If you come from one codebase to another codebase by a different team it’s close to learning a completely new language, but worse, there is no documentation I can find that will teach me only about that language.

Throw in all the versioning issues and the fact that .Net shops aren’t great about updating to the latest versions, especially because versions, although technologically separated from Visual Studio, are still culturally tied to it, and trying to break that coupling causes all kinds of weird challenges to solve.

Then stuff like extensions means your private codebase or a 3rd party lib may have added native looking functionality that’s not part of the language but looks like it is.

Finally, keywords and operators are terribly overloaded in C# at this point, where a keyword can have completely different meanings based on what it’s surrounded by.

LLMs are a huge help here, since you can point to a line of code and ask them to figure it out, but it still makes the process of navigating a C# codebase extremely challenging.

So I can see why someone may be unhappy to see yet another feature. It’s not just this one feature. It’s the 100s of other features that are hard to even identify.

Re: .NET (OK, C#) finally gets union types

#40
post #30
post #8

I used to see some excitement around .net core several years ago. I haven’t heard or seen much in the wild. Is anyone using .net on systems other than windows nowadays?

Yes; many (Alpine/Debian) containers in K8s on GKE for production rail ticketing infra in the UK. There's not tons of noise being made because for the most part it all, Just Works and that's fairly boring. Perf, memory usage etc gets better every release. As an ecosystem, I'm pretty happy with it. I reach for other languages for smaller microservices.

> rail ticketing infra in the UK

You mean Raileasy? Or RDG too? (Just curious about the stack of the wider rail tech infra)

Post reply on HN