5 ms·
Welcome to C# 11
- delta_p_delta_x 4y ago> Monoid T AddAll<T>(params T[] elements) where T : IMonoid<T> => elements switch { [] => T.Zero, [var first, ..var rest] => first + AddAll<T>(rest), }; It is remarkable how functional C# has become. Not that it wasn't very functional already, what with LINQ and its (much more powerful than Java) generics but the above example really hammers home how much FP has inspired C#, on top of Ocaml's influence on C# generics[0]. [0]: https://github.com/ocaml/cwn-data/blob/9ee93e99d984b3f922e2566eff5277233a305bfc/2006.11.21.text#L40 https://github.com/ocaml/cwn-data/blob/9ee93e99d984b3f922e25...
- vyrotek 4y agoI saw that and immediately thought, "Someone put F# in my C#!". Looks great.
- WorldMaker 4y ago> its (much more powerful than Java) generics Yeah, it's also interesting to point out how useful to FP C# 11's further improvements to generics are. Generic Math, which the IMonoid<T> in this example is a part of explaining a small related piece of (static abstract interfaces), is another place where C# is improving generics (further beyond Java). The list of interfaces in the much expanded System.Numerics namespace where most of the raw implementation of Generic Math lives should look quite interesting, if not familiar, to many FP developers: https://learn.microsoft.com/en-us/dotnet/api/system.numerics?view=net-7.0 https://learn.microsoft.com/en-us/dotnet/api/system.numerics... It will be interesting to see where libraries take Generic Math.
- david_allison 4y agoAlthough seldom used, C# has allowed for Haskell-style monadic comprehension syntax for decades via extension methods. It's very strong functionally var paymentId = from joshIban in processor.GetIban("josh") // fails from olenaIban in processor.GetIban("olena") // not executed from paymentId in processor.SendPayment(joshIban, olenaIban, 100) select paymentId; https://github.com/louthy/language-ext/wiki/Thinking-Functionally:-What-is-LINQ-really%3F https://github.com/louthy/language-ext/wiki/Thinking-Functio...
- ziml77 4y agoIt's been going that way since LINQ and I'm happy every time they move a bit more functional. I don't want my C# to be purely functional, but I love being able to choose to use functional constructs when I feel they work better.
- keewee7 4y agoLooking back at how HN and r/programming reacted to recent versions of C# the common complaints are that the language is becoming too complex and that it is hard to keep up with new features. The language has gotten a lot of new features but it is surprisingly viable to keep coding like it's 2012 when C# 5.0 came out with async/await support. It is also surprisingly viable for most C# programmers to not keep up with new language feature. Most are using ReSharper or Rider that will introduce useful new language features as a refactoring suggestion that is one shortcut away.
- kraig911 4y agoI am looking to learn C# coming from Javascript/Typescript. It just looks so complex to me and I feel I do not know what is going on. Everywhere I look I see strange examples seeing it change over time. What would you give as guidance to someone looking to pickup C#?
- Gibbon1 4y agoI think it looks complex because most of the new stuff you see are fancy additions to the language. But the older non-schmancy stuff is still there and works exactly as it always has. Your best bet is install visual studio (free) and start messing with it.
- philosopher1234 4y agoDoes this exact argument apply to c++?
- mk89 4y agoI believe it might. Not a C++ expert, but I am using Clion with lots of clang-tidy features and a lot of compiler warnings, and I believe that the code looks more modern. If you use a "new" you'll get right away warnings. Of if you declare a destructor without copy/move, you'll get also some warnings. It might piss people off, but for a new learner like me it's really useful. Plus, I don't have the luxury to count on my colleagues to get some code review, therefore the closest I get is the available tools (clang-tidy, clang-format and enable_developer_options in the project_options[0] extension). [0]: https://github.com/aminya/project_options https://github.com/aminya/project_options
- Arnavion 4y ago>If you need three or more "s to be part of your content, you just use more "s on the outside. The beginning and end just have to match: This particular form of raw strings would seem to have the problem that you can't start the raw string with a double-quote character. ie if you want: Console.WriteLine(???); ... to print: "Hello world" ... you can't write: Console.WriteLine(""""Hello world""""); ... because that'll print: Hello world I suppose the workaround is: Console.WriteLine(""" "Hello world" """);
- jp0d 4y agoWhat does the future of F# look like with C# becoming more and more functional?
- bobnamob 4y agoLikely a proving ground for yet more functional features
- shirogane86x 4y agoF# is still a lot more functional, has cleaner stuff for functional style coding (like the pipe and reverse pipe operator, function composition and custom operators). Computation expressions are still better than LINQ's comprehension syntax, imo. And I don't think C# is getting SRTPs or Type providers anytime soon. Another thing to keep in mind is that all of these changes are available to F# too, and static members in interfaces (plus some extra syntax goodness around SRTPs that they are introducing) are gonna be amazing (interfaces + static members are starting to look eerily close to typeclasses, in a good way)