Live data from Hacker News

Official proposal for Type Unions in C#

github.com

191–200 of 315 posts

Re: Official proposal for Type Unions in C#

#191

Earlier quoted context omitted.

I'm a Linux user who prefers open-source tools. I not a fan of Microsoft's programs, tools, editors, etc. What would you suggest I do to be productive with C#?

It's remarkably disappointing to see this question downvoted. I had the same thought, but this makes me wonder if it's just a bad culture fit from the start. I've been Linux-only now for 15 years and haven't used an IDE in well over 10. I use vim (neovim now) exclusively. Given my characteristics, should I just squash my curiosity and do a pass on C#? Do C# people not see value in open source? Is there low tolerance…

>Do C# people not see value in open source?

C# and dotnet are open source so what on Earth are you even talking about?

>squash my curiosity

Maybe increase your curiosity and try something new, change the 15 year trend and use an IDE. JetBrains Rider is great and cross platform.

"tolerance in that community for people who have those values"

More likely is they don't worry about this nonsense and just get work done, making a great language, platform and tools used extensively and productively in many companies. Why should they "think about you at all" as the meme goes?

Talk of culture, values, community, tolerance, "your characteristics". This all reeks of injecting extraneous personal feelings where they don't need to be. How about you just try the language, if you actually care to do so, and worry about the rest later?

Re: Official proposal for Type Unions in C#

#192

Earlier quoted context omitted.

I went from C# to JVM/gradle and have the opposite experience. 1) default C# IDE is junk compared to IntelliJ 2) Gradle give you insane level of control over project you can even build dynamic template tasks shown in IntelliJ UI using Kotlin/Groovy 3) JVM ecosystem is much bigger and default framework SpringBoot is ready to use with houndreds of integrations which are either non existent or hards to use in .NET as op…

What makes intellij so much better than visual studio or vscode?

those are two separate questions.

Compared to old VS: First and foremost: feature richness of refactorings, code inspections and plugins - basically in the IntelliJ you have everything Reharper plugin can do for .NET and probably more. Second IntelliJ can run on non-spying operating systems. Third it's much more resource friendly for bigger projects. Last but not least ItelliJ is keyboard user friendly (e.g. you can jump and resize windows using only keyboard).

Can't say much about vscode vs IntelliJ. When I tried it last time Java plugin was not there. I could not use ItelliJ keyboard shortcuts - also code formatting and refactoring options were worse than in the itelliJ. That's to be expected it's paid product after all.

Re: Official proposal for Type Unions in C#

#193
post #3

Huh, I did F# for years with discriminated unions, and I guess I just assumed C# would have had them by now. I know not everyone likes them, but for typed languages I find it extremely hard to go back to languages without ADTs of some kind. I do Java for my current job, and 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 b…

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…

what's is your .NET replacement ?

Re: Official proposal for Type Unions in C#

#194
Really excited for this proposal as it's been the main thing I have to apoligize for when extolling the values of C#. Outside of this it's hard to think of other major features C# lacks for a language.

Additionally, excited to now watch this go in and people on HN still act like C# is the same it was 10 years ago.

Re: Official proposal for Type Unions in C#

#195
post #167

Earlier quoted context omitted.

None of those are "widely distributed". They're all things that either MS themselves or MS-oriented shops run internally. No-one's writing a database server or identity management system or source code repository or business intelligence tool or even something like a linter in cross-platform C#. Unless you're a Windows shop, it's just not a first-class ecosystem.

You really should google before you make remarks... I'm also going to ignore the widely distributed remark because it is ridiculous. > No-one's writing a database server RavenDB, which can be run in a cluster, and uses less CPU (and I've read memory) than MongoDB itself. There's also a recent C# based redis drop-in replacement that outperforms redis. See more: https://github.com/quozd/awesome-dotnet?tab=readme-ov-fil…

> RavenDB

Ok, that actually sounds interesting. Still haven't heard of anyone using it, and closed-source makes it a non-starter, but I'm vaguely interested. Even then though, sounds like their client libraries are only .NET?

> As for identity, you sound really silly when you consider it is literally built-in to ASP .NET itself, and can be expanded upon to your hearts desire, plus there's no shortage of available identity management libraries in C#.

Sure there is plenty of support for it within the platform. My point is no-one's writing their organisational SSO system in C#, unless they're already bought into the Windows stack.

> As for source code repository, I'm not sure what you mean, but for years Microsoft hosted CodePlex which was essentially GitHub for C# projects.

I mean the equivalent of Bitbucket Server or GitLab, the thing you'd run to host your own source repos internally.

> I'm not even going to comment on business intelligence, now you're just being very lazy. You're telling me Microsoft has 0 BI tooling and SDKs?

No, I'm saying that what they have is all locked into the MS/Windows parallel world stack. There's nothing that a company that isn't committed to them would use.

> As for a linter, you are either trolling, or just blindly hate Microsoft for no rhyme or reason, there's more than enough linters, especially the best one of all, ReSharper, which is integrated into Rider which is a cross-platform IDE. There's also MonoDevelop, SharpDevelop, etc

There are plenty of linters for C#, sure. But no-one would write a general linter in it. It was an example that came to mind because that was how Facebook first started adopting OCaml - a linter is a small standalone tool, so it's an ok place to experiment with a new technology stack.

> Netflix's original web UI was Silverlight, which is C# / .NET back when it was at its peak for its time.

And look how that worked out for them.

Re: Official proposal for Type Unions in C#

#196
post #167

Earlier quoted context omitted.

None of those are "widely distributed". They're all things that either MS themselves or MS-oriented shops run internally. No-one's writing a database server or identity management system or source code repository or business intelligence tool or even something like a linter in cross-platform C#. Unless you're a Windows shop, it's just not a first-class ecosystem.

No linters in C#? That’s a good one. C# as a language has always been cross-platform. Though the last few versions have made incredible gains in performance optimizations. You won’t get the flexibility of C++ but the performance comes close to it in most cases, when written optimally. And you don’t have to deal with arcane, bullshit build systems with a learning curve that is worse than the language, and breaks down…

> C# as a language has always been cross-platform.

Not really. Like, it notionally ran on FreeBSD, but nontrivial programs never actually worked until recently, and even now they mostly still don't.

Re: Official proposal for Type Unions in C#

#197
post #96

Can anyone explain why this is called "type unions"? I've never heard it named that before. It's a bit weird, because it's not a union across types (like ALGOL68), it appears to be a tagged union like in ML-family languages. Is this just a case of "C# developers like to make up different names than established terminology"? (see: SelectMany, IEnumerable, etc.)

"Tagged" sounds like an implementation detail to me (that it has a "tag" internally to tell between types). I suspect they added "type" to "union" to make it clear what is about (about types). The syntax itself has just "union", judging by the document. UPD. They have this in the FAQ: Q: Why are there no tagged unions? A: Union structs are both tagged unions and type unions. Under the hood, a union struct is a tagged…

I don't think tag is an implementation detail generally, for example:

    enum Option {
        None,
        Some(T),
    }
The tags are "None" and "Some" which are definitely user facing.

But I see what they mean a bit with the C# example:

    union U 
    {
        A(int x, string y);
        B(int z);
        C;
    }
So it seems like "A", "B", and "C" are tags but also their own distinct types, with a implicit conversions between those and the overall union type

Re: Official proposal for Type Unions in C#

#198

It’s ironic when things like this get added back into C-styled languages that were intended to be easier than their predecessors. Seems more confusing than useful. Wish they’d stop adding onto this ever expanding language. It’s like these people get bored of plain old functions and objects, read an academic paper and go “i think I’ll add that next”.

> Seems more confusing than useful. Are you suggesting that these design decisions make it through the entire process and into the language without the feature bringing a clear advantage in its use case? What would you say are the worst two or three of these C# features approved in the last decade? Let’s assume for the sake of argument that you are correct though. The Roslyn compiler diagnostics are second to none, a…

> These guys aren’t writing feature proposals the way you write comments.

You’re comparing the effort of a mainstream language design proposal to a pseudonymous internet comment, wow, just wow.

Do you truly know real software developers using any these new features? I must not be working anywhere cool because I’m always having to explain what they mean in code reviews.

Imagine writing a full C# compiler in 2024, imagine if one possibly could with all these different features in this big big language.

> Are you suggesting that these design decisions make it through the entire process and into the language without the feature bringing a clear advantage in its use case?

I’m suggesting they don’t end up being adopted by enough people to be convincing. To me that leads to the shared problem with cpp, feature bloat. Multiple ways of achieving the same thing.

Since you asked, these are the three off the top of my head.

1. Init keyword is strange, why specify an accessor that only seems to apply during initialization? We already have read only for constructors. I always felt initializing objects with brackets (whatever they hell they call it) was something meant for more casual code where assignment isn’t enforced or restricted.

2. Switch expressions are ridiculous. They can get hard to read, alienating non C# programmers who come from C styled backgrounds, part of what made this language successful to begin with. They seem more like yet another syntax sugar we have to learn. And to your Roselyn comment, a language shouldn’t be dependent on Roselyns analysis to actually be usable to the general public. That is not what I’d call a cross platform language, that’s a monopolistic one where Windows/Visual Studio is the only place a not .net fanatic such as yourself can easily get work done.

3. Nullable Reference Types further over complicates what used to be a simple system of reference and value types. On top of the already head scratching nullable value types which made people question why they initially moved away from javas only reference type concept to begin with.

Slightly off topic but we have at least 3 ways to define record types: tuples, structs, and now records. I actually do like record types but unfortunately now existing code bases are polluted with the former. The point I’m trying to make in this last statement is I feel they aren’t careful enough with their proposals. They got it right with records, but look what they brought us along the way.

Re: Official proposal for Type Unions in C#

#199
post #172
post #165

Earlier quoted context omitted.

I wrote c# professionally for 8 years and now have switched to a codebase mostly in Java and some kotlin. I know some of this is learning curve but none of those things mentioned are anywhere close in JVM. Build systems, package management, close IDE integration for test runners, builds, etc. The ability for the IDE to even know what version of Java you want the project to run in even though it's defined in the proje…

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.

Re: Official proposal for Type Unions in C#

#200
post #13

Is the terminology slightly off? AIUI TypeScript has type unions. But this looks like a discriminated union which I'd recognise from F# or Haskell. The distinction I'd draw is that for a DU there are named case constructors. Yes?

Going from C# to Typescript with type unions it always felt weird. Maybe that’s a good reason to have held off on this for this long? Know your audience and all that?

It does get used to but still reading the too many A|B|undefined gets tiring after a while. It also adds to laziness as you could take one thing and be fuzzy about returning a combo of three or more things. And as you go up the stack this gets more and more confusing.

C# forces you to deal with this in a constrained way which I like.

But perhaps there are folks who are excited by this that have a convincing argument? Please educate me.

Post reply on HN