by alkonaut · 11y ago · 0 comments
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.
If C# gets these improvements there will be millions of lines of C# that could get better without C# programmers having to learn F#.
I maintain a bunch of C# codebases, and I'd love to have more updates to the language.
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.
However, that doesn't mean we don't wish you wouldn't have to specify the type there -- that's why there's a separate proposal for local functions (https://github.com/dotnet/roslyn/tree/features/local-functio...), which would allow
var inc(x) => x + 1;So with that, local functions will have different syntax than normal functions? I don't envy y'all on the C# team; it's gotta be difficult to try to advance it while maintaining backcompat.
I just wish MS would put more money and clear marketing into F# instead of pretending like hacking up C# syntax is the only way to continue.
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.
As for things changing with type inference... if you run into that problem then add annotations. I'd be surprised if things continue to build after changing e.g. return types. I'd imagine this would only really be a problem with types that have implicit conversions (yet another reason to not have implicit conversions.)
1: http://blogs.msdn.com/b/ericlippert/archive/2009/01/26/why-n...
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.