Live data from Hacker News

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

andrewlock.net

21–30 of 300 posts

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

#22
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?

it was an obvious marketing campaign. back then core and blazor were shilled relentlessly, and the artificial excitement died the moment MS moved on to shill vscode and typescript.

companies spend a lot on marketing, and it's not just ads.

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

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

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

#24
post #5

AFAICT, this means you won’t be able to define Either , which is definitely a thing you sometimes want to do.

C# is strongly-typed, not stringly-typed. The point of the union is to list possible outcomes as defined through their respective types. The idiomatic way to do this would be to parse, don't validate [1] each string into a relevant type with a record or record struct. If you just wanted to return two results of the same type, you'd wrap them in a named tuple or a record that represented the actual meaning. [1] https:…

I guess C# is more strongly-typed than Haskell then... /s

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

#25

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]

thanks for helping.

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

#26

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.

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.

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

#27
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?

I consulted for multiple enterprise C# projects in the last 5 years. At least two of them are 1mil+ lines of code each.

All of them run in Linux servers.

Some of them were ported from PHP and Python to C#.

Plus LLMs thrive in strongly typed languages.

Which means C# will keep being very strong in enterprise too. Not only in games where it reigns a large chunk of the market share.

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

#28

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.

A common use case for the sum type is to define a Result (or Either) type. Now, C# not having checked exceptions is not as much in need for one as Java is, but I could still imagine it being useful for stream like constructs.

yeah this is the one I've considered as being mildly compelling. But don't we lose the fun of having exception handling as separate to the happy path?

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

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

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

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

Post reply on HN