Live data from Hacker News

Official proposal for Type Unions in C#

github.com

111–120 of 315 posts

Re: Official proposal for Type Unions in C#

#111
post #12

Every time the question of preferred programming languages comes up, I'm usually in the extreme minority with my preferences being Rust (for small/fast) and C# (for productive and easy, where GC is acceptable), a combination that doesn't seem to appeal to too many people. But for the projects that fall right about in the middle where it could go either way and I could see either language working, I almost always pick…

Instead of C#, why not F#? You get proper ADTs among many other great features, but you still get all the utility of the .NET ecosystem.

Because nobody uses it, Microsoft doesn’t invest or promote F# heavily. I’m pissed about all of this, but I accept that eventually C# will get much of F#’s goodness.

Re: Official proposal for Type Unions in C#

#112
post #4

Earlier quoted context omitted.

F# is so hard to walk back from. I wish Microsoft would support it better and actually push it, because it's such a perfect sweet spot. Most of the functional advantages without being shackled to pure functions and the like is so easy to develop in. Instead they've been, very slowly, turning C# into F#, which is even weirder to watch.

I'm glad they're simply turning C# into F#. They're coming to us where we are, rather than forcing us to make a jump. I'm a relatively "blue collar" developer, I know a little about FP (not enough to be productive in F#) but I have tons of C# experience. I appreciate them taking the good stuff from F# and making it understandable to C# developers. It's been a delightful progression; no big jumps, no paradigm shifts,…

I agree with you, as far as adding new features to C# from F#. When I have the time to refactor larger codebases, I'm often finding new C# features/syntax makes the code easier to understand and reason about (often due to decreasing the number of lines needed to accomplish the same thing, without overcomplicating things). I do make sure that if I'm introducing new language features, that I'm refactoring related portions of code, so I'm not leaving behind the "old" way of doing things while also introducing the "new" way for the same functionality. I'm always thinking of the next developer with anger issues coming into the codebase after me.

Re: Official proposal for Type Unions in C#

#113

I always think it's a shame that instead of C# becoming a better OO language, they keep trying to become an uglier F#. IE, why is the syntax for multiple dispatch still so clunky? I know I know, pseudo OO took over the world, and then people revolted against it, so the easiest thing to do to stay relevant is to become "slightly functional with curly braces", rather than to actually try and do OO well.

I have the same objection but coming from the other side. The mainstream languages used to have pervasive mutation and side-effects. Now they have pervasive mutation and side-effects with lambdas.

But my question is: what is missing from the OO side? What would it take for C# and/or others to "do OO well"?

Re: Official proposal for Type Unions in C#

#114

Every time the question of preferred programming languages comes up, I'm usually in the extreme minority with my preferences being Rust (for small/fast) and C# (for productive and easy, where GC is acceptable), a combination that doesn't seem to appeal to too many people. But for the projects that fall right about in the middle where it could go either way and I could see either language working, I almost always pick…

I've been writing C, C++, C# and some js/sql/ts/python for money. Lua for lulz.

And *nothing* gets even fucking close in terms of productivity to C#.

Great language, mature and robust ecosystem with sane compilation times and

great tooling: package manager, test runner, strong debugger, one CLI with almost all tools needed.

I wish C++ was half as enjoyable as C# is.

Re: Official proposal for Type Unions in C#

#116
post #72

Earlier quoted context omitted.

> It's impossible for a .NET library to not work with F#. This isn't true, C# has been adding new ABI features that didn't interact correctly with F# until the compiler and tooling catched up. For example, the spanification of C# was a huge a pain point and it still is when it comes to tooling.

TIL. Have links to any details about this? I'm very curious!

You mostly have to look at the time frames between C# adding features with new ABIs and the time it takes for F# to announce they can actually consume them.

For example, F# used to crash the CLR with InvalidProgramException when setting C# `init` properties. [1] It took almost three years, I think, to release the fix.

[1]: https://github.com/fsharp/fslang-suggestions/issues/904

Another rough example would be spans, and their more general feature, byref-like types (ref struct). These required plenty of compiler support, as they've got special lifetime rules (and more pending to implement `scoped`), they are banned as generic type arguments, and they require ignoring a special Obsolete attribute.

While these were added to F# timely, many language features still break when they interact with them: local functions, computation expressions (even the built-in ones), recursive type inference, and generic intrinsic methods such as `raise`, `defaultof` or `typeof`.

This wouldn't be so bad if C# hadn't "spanified" the shared framework and the entire ecosystem without CLS alternatives for many APIs.

So, these natural F# snippets don't compile:

  let numbers = [| for span in text.EnumerateLines() -> Int32.Parse span |]

  let checkNonEmpty (span: ReadOnlySpan) =
      if span.Length > 0 then span else failwith "Expected non-empty span."
Edit: And I haven't even gotten into the libraries that use reflection expecting you to declare types in ways F# doesn't support.

Re: Official proposal for Type Unions in C#

#117
post #113

I always think it's a shame that instead of C# becoming a better OO language, they keep trying to become an uglier F#. IE, why is the syntax for multiple dispatch still so clunky? I know I know, pseudo OO took over the world, and then people revolted against it, so the easiest thing to do to stay relevant is to become "slightly functional with curly braces", rather than to actually try and do OO well.

I have the same objection but coming from the other side. The mainstream languages used to have pervasive mutation and side-effects. Now they have pervasive mutation and side-effects with lambdas. But my question is: what is missing from the OO side? What would it take for C# and/or others to "do OO well"?

To be clear I don't really come from "the other side". I very much enjoy and like functional programming. But again, that's what F# is for, right? If we push the state of the art in another directrion, the whole landscape benefits more - because I think we both agree C# is never going to be a better FP language than F#.

As for what C# could do better, the OO solution to the problem pattern matching solves is multiple dispatch - with single dispatch languages you need things like the visitor pattern. Making that a first class part of C# would be fantastic.

https://shawnhargreaves.com/blog/visitor-and-multiple-dispat...

Re: Official proposal for Type Unions in C#

#118

Every time the question of preferred programming languages comes up, I'm usually in the extreme minority with my preferences being Rust (for small/fast) and C# (for productive and easy, where GC is acceptable), a combination that doesn't seem to appeal to too many people. But for the projects that fall right about in the middle where it could go either way and I could see either language working, I almost always pick…

You must really hate REPLs. You cling to your ADTs, I cling to my REPLs.

I can’t speak to Rust but there have been plenty of C# repls in the past.

https://fuqua.io/CSharpRepl/ For one

Re: Official proposal for Type Unions in C#

#119
post #97

Earlier quoted context omitted.

I definitely dislike most C#/.NET developers/community (every time mediator is mentioned I want to stab myself) and would rather work with people in F#/FP. But when you have to work on "diverse" development teams having some sort of patterns established (flawed as they are) brings some order to the insanity.

My brain really likes how organizes C# libs tend to be compared to the 50 different organization schemes I deal with in node and python

Does C# impose a lot of organization? I've only worked in one C# codebase but it has partial classes everywhere and TONs of abstraction bloat. I found it difficult to reason about the organization.

Re: Official proposal for Type Unions in C#

#120
post #113

I always think it's a shame that instead of C# becoming a better OO language, they keep trying to become an uglier F#. IE, why is the syntax for multiple dispatch still so clunky? I know I know, pseudo OO took over the world, and then people revolted against it, so the easiest thing to do to stay relevant is to become "slightly functional with curly braces", rather than to actually try and do OO well.

I have the same objection but coming from the other side. The mainstream languages used to have pervasive mutation and side-effects. Now they have pervasive mutation and side-effects with lambdas. But my question is: what is missing from the OO side? What would it take for C# and/or others to "do OO well"?

> What would it take for C# and/or others to "do OO well"?

Multiple inheritance. (j/k)

Post reply on HN