6 ms·
C# will be a force to reckon with if/when discriminated unions finally land as a language feature.
by ComputerGuru 1y ago
C# will be a force to reckon with if/when discriminated unions finally land as a language feature.
- CharlieDigital 1y agoI think people who last looked at C# 10 years ago or haven't adapted to new language features seriously don't know how good C# is these days. Switch expressions with pattern matching are absolutely killer[0] for its terseness. Also, it is possible to use OneOf[1] and Dunet[2] to get access to DU [0] https://timdeschryver.dev/blog/pattern-matching-examples-in-csharp https://timdeschryver.dev/blog/pattern-matching-examples-in-... [1] https://github.com/mcintyre321/OneOf https://github.com/mcintyre321/OneOf [2] https://github.com/domn1995/dunet https://github.com/domn1995/dunet
- ComputerGuru 1y agoI write C# and rust fulltime. Native discriminated unions (and their integration throughout the ecosystem) are often the deciding factor when choosing rust over C#.
- CharlieDigital 1y agoVery hard to imagine teams cross shopping C# and Rust and DU's being the deciding factor. The tool chains, workflows, and use cases are just so different, IMO. What heuristics were your team using to decide between the two?
- azkalam 1y agoThis surprises me. If you want the .NET ecosystem and GC conveniences, there is already F#. If you want no GC and RAII-style control, then you would already pick Rust.
- mhh__ 1y ago> OneOf I do like/respect C# but come on now. I know they're fixing it but the rest of the language was designed the same way and thus still has this vestigial layer of OOP-hubris
- CharlieDigital 1y agoIt's up to each team to decide how they want to write their code. TypeScript is the same with JS having a "vestigial" `class` (you can argue that "it's not the same", but nevertheless, it is possible to write OOP style code in JS/TS and in fact, is the norm in many packages like Nest.js). The language is a tool; teams decide how to use the tool.
- vips7L 1y agoFor me, it will be if they ever get checked errors of some sort. I don’t want to use a language with unchecked exceptions flying about everywhere. This isn't saying I want checked exceptions either, but I think if they get proper unions and then have some sort of error union type it would go a long way.
- CharlieDigital 1y agoYou can get an error union now: https://github.com/amantinband/error-or https://github.com/amantinband/error-or
- vips7L 1y agoThe issue is the ecosystem and standard library. They still will be throwing unchecked exceptions everywhere
- raddan 1y agoI hear what you’re saying but the C# standard library is pretty well-behaved. If you’re really that concerned about it, wrap questionable calls in an exception handler and convert them into option types, and then you can force everything downstream to handle all the errors. I share your dislike of unchecked exceptions; sadly checked exceptions also kind of suck. Working in old Java codebases that use them is torture.