News for hackers. Stuff that matters.
Re:Official proposal for Type Unions in C# by kriiuuu on Wednesday August 07, 2024 @01:59PM (#41183727)
Good news is that you can achieve this with relatively little boilerplate in Java with sealed interfaces and records now. Relative to Java that is
Re:Official proposal for Type Unions in C# by tombert on Wednesday August 07, 2024 @02:02PM (#41183755)
Yeah, I know, and I have started using those, though that doesn't undo the last 15 years of Java code that I've written where that wasn't really an option.

Still, good to see Java joining the 21st century at least.

Re:Official proposal for Type Unions in C# by cies on Thursday August 08, 2024 @04:21AM (#41189287)
> that doesn't undo the last 15 years of Java code that I've written where that wasn't really an option.

Same for C# with this new feature. Sum types (as I like to call tagged/type unions) are such an important tool to have, not having it makes languages resort to all kinds of abominations, e.g. exceptions, product types (= records, structs, etc) that are actually sum types, "null to signify something went wrong", etc.

Not having them from a language's start results in an std lib that does not use them and hence teaches new comer to the language a bad way to do it.

Re:Official proposal for Type Unions in C# by karmakaze on Wednesday August 07, 2024 @07:48PM (#41186691)
Java can't do the ad-hoc mixing of types from different libraries, which is something I've wanted/needed for some ORM+expressions work I was doing. I really like where C# is going with this. Hopefully it will accelerate continuation of the evolution of Java.

I'm almost of the mind to use F# or C# instead of waiting.

Re:Official proposal for Type Unions in C# by bad_user on Wednesday August 07, 2024 @09:58PM (#41187406)
Those are untagged union types and are less useful than you think.

For one, they don't work for generic code where you want to discriminate. I.e., if you have a generic A or B type, you can't pattern match on it. And it's hard to add restrictions to the generic types such that it would work.

Such types sort of work in TypeScript, but TypeScript also has structural typing, meaning that it's designed for it.