Live data from Hacker News

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

andrewlock.net

261–270 of 300 posts

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

#261

Earlier quoted context omitted.

Java Virtual Threads are a superior paradigm to C#'s async/await and function coloring.

I don't get what the big problem is with function coloring. You basically only need async when doing IO, and you had better know when a function does it, or you may have a bad surprise at some point in the future.

Agreed, async function coloring makes for better structured code because it incentivizes keeping IO code near the edges while having a synchronous core.

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

#262
post #250

Earlier quoted context omitted.

> I think operator overloading would be a very bad feature for an enterprise language like Java which needs to be consistent above all else. Operator overloading increases consistency. Instead of having int a = b + c; CustomNumberType x = y.add(z); you have int a = b + c; CustomNumberType x = y + z;

The problem with operator overloading is it makes things confusing when mixing types and let's programmers write confusing code. Person x; Job y; CustomType z = x + y; WTF is Z? Is the argument, anyway, I support operator overloading.

> WTF is Z?

Hopefully a type error, because no sane programmer would implement addition like this. Obviously an insane programmer could, but that’s not the fault of operator overloading. The following code is exactly as confusing:

    Person x;
    Job y;
    CustomType z = add(x, y);

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

#263
post #70

Earlier quoted context omitted.

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

Because Microsoft pushes C#/dotnet as the preferred way to write UI on Windows.

Which, for specifically Windows, it works perfectly fine. The only complaints I've heard is for a cross-platform UI framework.

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

#264
post #185
post #108

Earlier quoted context omitted.

Do you think by now C# has left Java behind in features and performance?

C# was always better than Java as a language. The strength of Java is the ecosystem, and Java being open source and cross-platform from the beginning.

That used to be the case, but I would argue that C#'s ecosystem is just as competitive now. For our backend tech stack at work, all of our libraries used are open source nugets. Back 15 years ago, paid nugets were definitely more standard.

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

#265

Earlier quoted context omitted.

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?

oo and support for exceptions, in particular checked exceptions, was a mistake of the 90s. We know better today, there’s a reason for why modern languages like go/rust/swift don’t use them, and why many use c++ with exceptions disabled.

Checked exceptions are great. There is no difference between them and results/unions except syntax. The below all express the same thing. Swift in fact uses the checked throws syntax.

    Result fn()

    T | E fn()

    T fn() throws E

    fn() throws(E) -> T

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

#266
post #262

Earlier quoted context omitted.

The problem with operator overloading is it makes things confusing when mixing types and let's programmers write confusing code. Person x; Job y; CustomType z = x + y; WTF is Z? Is the argument, anyway, I support operator overloading.

> WTF is Z? Hopefully a type error, because no sane programmer would implement addition like this. Obviously an insane programmer could, but that’s not the fault of operator overloading. The following code is exactly as confusing: Person x; Job y; CustomType z = add(x, y);

I don't know; you can bit shift an output stream by a string (or char array) in C++ (std::cout << "Hello, world!"). That seems pretty mad to me.

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

#267

Earlier quoted context omitted.

C# used to be my favorite language, but having spent a lot of time in Rust using its algebraic data types + match statements + Option & Result types, then returning to C# to build a few moderately involved libraries, I'm horrified by the enums and null & error handling that I used to deal with all the time. I knew that enums were really just named integer values and nothing more, but I had forgotten than you can buil…

> I had forgotten than you can build a perfectly legal enum from an integer out of the bounds of the enum's range. And a switch statement is non-exhaustive These are solved by the new feature described in the article that we're commenting on right now. They're giving us unions and exhaustive switch. Ctrl+F "canonical way to work with unions" in the article to see an example. One of the best parts about C# is they nev…

And one of the worst is how long it takes them to implement even simple things. There are parts of the language (Expression) that are 20 years behind the rest and they don’t see the problem.

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

#268
post #70

Earlier quoted context omitted.

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.

Because people have given up that battle and just except that Java UI is crap.

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

#269
post #266
post #262

Earlier quoted context omitted.

> WTF is Z? Hopefully a type error, because no sane programmer would implement addition like this. Obviously an insane programmer could, but that’s not the fault of operator overloading. The following code is exactly as confusing: Person x; Job y; CustomType z = add(x, y);

I don't know; you can bit shift an output stream by a string (or char array) in C++ (std::cout << "Hello, world!"). That seems pretty mad to me.

Are you trying to imply that Bjarne Stroustrup is a sane programmer?

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

#270
post #84
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 is better than ever. You can use it with .NET10 and WebView2 is a thing now.

Responsive UI, fluent styling, are they straightforward now, or do you still need to jump hoops?
Post reply on HN