Live data from Hacker News

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

andrewlock.net

61–70 of 300 posts

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

#61
post #49

Earlier quoted context omitted.

but can you define T1 and T2 of string, then use Either ?

Could you be clearer about what you mean, since string is a sealed type in C#, so what exactly do you mean T1 and T2 of string?

A record wrapping a string, indicating what the string represents, so you can't mix it up with a different thing also represented by a string.

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

#62
post #53

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.

This is a classic debate in programming, literally: 2001: "Beating the Averages" (Paul Graham) [1] 2006: "Can Your Programming Language Do This?" (Joel Spolsky) [2] Both of these articles argue for the thesis that programmers that have been deprived of certain language features often argue that they don't need those features since they are already comfortable working around the lack of said features. It's a fancy way…

I can already do functional programming like map/reduce in C# tho. Not sure what the LISP argument is. Spolsky was saying there's a perf benefit in there somewhere but I'm not seeing how unions give me that.

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

#63

Earlier quoted context omitted.

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

Isn't that just Func ?

Really not. You can, of course, having instead a delegate to evaluate the expression. But then that's all you can do. You can't pretty-print it, for example, or optimize it, or whatever.

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

#64
post #2

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

What types of problems are better solved in F# than C#? Is having a combination of F# and C# in a single codebase possible? Is it recommended?

Easy code is much easier in f#, a lot of the time. Hard code is usually easier in f# due to the type system helping a lot. F# is also a lot more concise.

And yes, you can combine them, but afair, only in terms project boundaries. (You can include a c# project in an f# one and vice versa). There are a few cases where it's quite useful. For example, rewriting a part of a big project in f# to leverage the imperative shell - functional core architecture. Like rewriting some part that does data processing in f#, so that you can test it easier/be more confident in correctness, while not doing a complete rewrite at once.

Sort of like rust parts in the linux kernel.

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

#66
C# is my strongest and favorite language. That said, it's frustrating that the C# framework ecosystem lacks solid options. MAUI is especially half-baked, and I'm really starting to doubt whether I should continue using XAML

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

#67
post #53

Earlier quoted context omitted.

This is a classic debate in programming, literally: 2001: "Beating the Averages" (Paul Graham) [1] 2006: "Can Your Programming Language Do This?" (Joel Spolsky) [2] Both of these articles argue for the thesis that programmers that have been deprived of certain language features often argue that they don't need those features since they are already comfortable working around the lack of said features. It's a fancy way…

I can already do functional programming like map/reduce in C# tho. Not sure what the LISP argument is. Spolsky was saying there's a perf benefit in there somewhere but I'm not seeing how unions give me that.

You have at least two options:

1. Argue from ignorance. Never try unions in any other programming languages and completely disallow their use in C# codebases that you participate in.

2. Try them out and adopt an informed opinion.

You may even choose to remain in ignorance until someone wastes their own time trying to convince you. But it isn't my job or desire to teach someone who won't put in the effort to learn for themselves.

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

#68
post #66

C# is my strongest and favorite language. That said, it's frustrating that the C# framework ecosystem lacks solid options. MAUI is especially half-baked, and I'm really starting to doubt whether I should continue using XAML

Winforms, wpf, blazor, maui, avalonia, what are you talking about

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

#69
post #66

C# is my strongest and favorite language. That said, it's frustrating that the C# framework ecosystem lacks solid options. MAUI is especially half-baked, and I'm really starting to doubt whether I should continue using XAML

Winforms, wpf, blazor, maui, avalonia, what are you talking about

Alright. I'm actually fine with WinForms and WPF since my factory floor codes depend on them. But the reality is they aren't expressive enough for modern UIs. XAML is an issue, and WPF is boilerplate hell. But then Blazor is too heavy, MAUI is broken and buggy, Avalonia is underwhelming, and WinUI 3 is an absolute nightmare.

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

#70
post #66

C# is my strongest and favorite language. That said, it's frustrating that the C# framework ecosystem lacks solid options. MAUI is especially half-baked, and I'm really starting to doubt whether I should continue using XAML

Winforms, wpf, blazor, maui, avalonia, what are you talking about

What I don't get is why Java doesn't get dogged for desktop UI like C# does.
Post reply on HN