6 ms·
While I think these C#7 proposals are all cool features (Non-null, tuples, pattern matching), it feels almost like it's too late to make improvements of this ki
by alkonaut 11y ago
While I think these C#7 proposals are all cool features (Non-null, tuples, pattern matching), it feels almost like it's too late to make improvements of this kind to C#. We have had F# for a very long time, do we really need non-null and pattern matching and so on in C#? The features sure make sense for C#, but do they make sense now?
As more and more features come into C#, all of the BCL would have to be updated to use them if they are to deliver their full value. When generics entered in .NET 2.0, the generic and non-generic collections API were both included in the BCL, and they still are. I can't see how it would be as easy to make the BCL take full advantage of proper tuples, non-nullables etc., in a way that doesn't feel like a complete afterthought.
I'm all for adding features, and I'd be happy to get breaking changes and update thousands of lines of code to get them. But I fear that isn't going to happen, instead things will come in as optional features, the BCL won't be updated to return tuples where it should (I.e. whereever it would have if the feature had been around forever), and so on.
- AndrewDucker 11y agoIt might be too late to update the BCL with them. But that doesn't make it too late to bring the updates to people who work with C# all the time. I maintain a bunch of C# codebases, and I'd love to have more updates to the language.
- MichaelGG 11y agoUnfortunately, since people are dumb[1], we're stuck with C#. So they might as well improve it as much as possible. This feature could be layered on top of the BCL as extra metadata. Sorta like TypeScript allows you to add type annotations to third-party libraries, C# could take that approach with null. (Yes, this is sorta ugly.) With tuples, C# can take F#'s approach and special-case common patterns (like TryParse that use out parameters). There's probably only a few patterns where this matters and you'd get most of the benefit. (And I suppose you could always provide annotations to note how to match certain non-tuple-returning functions.) 1: There's really no reason to use C# when we have F#, unless the app is some crap LOB app where programming style/syntax would be the highest barrier to entry. Even then I am suspicious. Anyways there's a lot of untalented developers that apparently cannot cope with FP, or much of anything really, and managers that are scared of different languages.
- sedatk 11y agoF# syntax is too verbose for OOP. Actually functional parts are too, like lambda syntax, LINQ etc. Unless it's improved C# is bound to remain mainstream.
- nbevans 11y ago"F# syntax is too verbose for OOP." Wow. First time I've ever heard that.
- MichaelGG 11y agoCan you explain? In C#, for example, type inference barely works. You have to do e.g.: Func<int, int> inc = x => x + 1; In F#, this is just: let inc x = x + 1 Based off a simple test (coded same thing in both languages), C# requires about 20x more type annotations. Fields, methods, type parameter constraints -- C# simply doesn't implement type inference in most places. You're right that F#'s lambda operator (fun) should be shorter. I'd prefer \. i.e. map (\x.x+1) But verbosity isn't the reason C# devs don't switch to F#. Hell, it's still a "thing" to decide if using "var" is ok.
- sixbrx 11y agoI'm not sure \ is better than "fun", fun does have a certain clarity when reading code, and it's only three extra keystrokes if you include the space, all easier to type than backslash which needs a pinky stretch. Honestly I could go either way though. Also note that C# loses brevity as soon as there are more args than one (such as with commonly used Seq.iteri or folds) because of having to type the "(,)" for C# (the parens annoyingly requiring shift keys) instead of just a space.
- CmonDev 11y agoMicrosoft funds F# as a test playground for future C# features.
- Locke1689 11y agoTo put it simply, the amount of C# code written makes F# look like a rounding error. If C# gets these improvements there will be millions of lines of C# that could get better without C# programmers having to learn F#.