Live data from Hacker News

Official proposal for Type Unions in C#

github.com

261–270 of 315 posts

Re: Official proposal for Type Unions in C#

#261

That proposal doesn't mention how the union struct handles tearing under concurrent modification. Tearing can cause memory safety issue. Variant A can have an integer field and variant B can have a reference field in the same offset. Tearing can cause it to treat an integer as reference.

The design is not going to allow for struct layout to have memory safety issues when tearing is involved. That is a problem we are very well aware of and consider in designs.

Re: Official proposal for Type Unions in C#

#262
post #18

What would the rough timeframe be for seeing adoption of this into the language? I was considering introducing the OneOf library into our codebase, but if this is < a year or so away it might not be worth the effort.

There is no timeframe right now. At the moment this is a loose proposal for how to approach union like features in C#. There are a lot more details to dig into here before we'd be ready to move to scheduling and implementation. Also need to decide if we take on all of the union variants proposed or just some and what priority order to approach them.

Re: Official proposal for Type Unions in C#

#263

Earlier quoted context omitted.

> Java is generally fine enough, but it's a little annoying when I have to do whacky workarounds with wrapper classes to get something that would be done in three lines This is a weird take, given that Java has had ADTs for years Records https://en.wikipedia.org/wiki/Java_version_history#Java_16 Sealed classes https://en.wikipedia.org/wiki/Java_version_history#Java_17 And pattern matching for almost a year https://en…

Most of my jobs until recently have been using Java 11, so I didn’t get to use these things.

I see. But no hope is lost! You can always lean on Scala. It runs fine on any Java >= 8 and it's great. Unless you intentionally used is badly (but you could say that about any language).

Re: Official proposal for Type Unions in C#

#264
post #199
post #172

Earlier quoted context omitted.

This is definitely all just a learning curve on how to do this. None of this is accurate at all. - IntelliJ knows exactly what version of Java you want to run and develop against. - Async is also trivial. Just fire off a virtual thread. - it sounds like your company just picked a bad orm. Any good one is going to escape sql injection when binding variables. You are using binding right? If you to “write it in Java” th…

I'm not worried about SQL invitation so much as I'd rather just query my C# objects instead of writing raw SQL. Yuck.

Java has that. It's just not the default choice because there is no default choice like in .NET. The options I know of: QueryDSL, jOOQ, Ebean with generated query beans.

Re: Official proposal for Type Unions in C#

#265
post #237

Earlier quoted context omitted.

As of 2020 (when I stopped using F# and .Net in general), the CLR only had inheritance and F#'s enums were actually implemented using inheritance. Eg Some and None were derived classes of Option class. You would see it if you inspected an F# assembly in a decompiler. I don't know if it's still the same today. This C# proposal has anonymous enums using `A or B` syntax which would be hard to make work as sugar over inh…

This is only partially true. Both Some and None were always instances of single FSharpOption class (None is actually not an instance, but null), however custom DUs are indeed compiled into classes with inheritance

Ah, then I misremembered.

Re: Official proposal for Type Unions in C#

#266
post #206

As a long time C# dev, I feel like I’m missing something about this proposal. The use case for this doesn’t seem well defined to me. Could someone give me a real world example? I’m pretty sure you can implement the example in this proposal by declaring an empty interface and having some record classes that “implement” it. Does that lose something that I’m not seeing?

We have been using empty interfaces to simulate F# discriminated unions for the last 5+ years. It works like a charm. The problem "not all cases are handled in the switch" occurs very rarely (once per 50k lines of code) and, usually, we fix it after the first run of a smoke test. So, it's not a problem at all.

I think,.net team haven't added discriminited unions yet because it can be effectively simulated with interfaces.

Re: Official proposal for Type Unions in C#

#267

Earlier quoted context omitted.

This comment is kind of out of the blue because no one in this thread is advocating for using C# for infrastructure projects. Java is frankly a bad choice for that too these days for a new project, and for the same reason: why would you develop infrastructure in a language that requires shipping a runtime when Rust and Go exist? That made a lot more sense back when C/C++ was your only other real choice. Meanwhile, pl…

Java has been fine for infrastructure projects. There is so much out there that relies on things like elasticsearch, Kafka, or any aws service. Heck even the columnar dbs like pinot and Druid are most likely more used than clickhouse. C# is also fine for this, just way less popular. Recently ms put out https://github.com/microsoft/Garnet when the redis debacle happened. The Apache project has helped put out quite a f…

ClickHouse is more widely used than Pinot or Druid based on any possible metric.

If you try to install any of the latter, it will be apparent why. (They are poor in usability).

Re: Official proposal for Type Unions in C#

#268
post #137

Earlier quoted context omitted.

If it wasn't so linux distribution unfriendly…

I've found it quite easy to build and deploy to Linux, also curious what challenges you've run into.

If it can't be included in the distribution, it's not "distribution friendly"

Re: Official proposal for Type Unions in C#

#270
post #137

Earlier quoted context omitted.

If it wasn't so linux distribution unfriendly…

What distributions specifically have you had a problem developing on? I've developed on Ubuntu and Pop_OS! in C# for years and never hit a problem.

Can I apt-get install your software? If not, then you've just hit the problem.
Post reply on HN