3 ms·
Does C# still require you to write everything with classes? Would love to try it if there's option to write functional code in it.
by ridiculous_leke 2y ago
Does C# still require you to write everything with classes? Would love to try it if there's option to write functional code in it.
- vunderba 2y agoThey introduced the concept of top-level scripts a little while back - though I don't know whether its just syntactic sugar such that when it compiles down to IL everything just gets wrapped in a main class. https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
- sedatk 2y agoIt's just syntactic sugar. That said, a static class with static methods is basically a namespace.
- intrasight 2y ago"classitis" is much diminished
- Kerrick 2y agoI’ve heard it’s multiparadigm now, but I can’t yet substantiate that. Even if it is, I don’t know if it’s JavaScript-level (so functional they rewrote SICP in JS), Ruby-level (just a sprinkle of lambdas and pattern matching), or somewhere in between. I’ll be sure to post an article once I find out. :-)
- webprofusion 2y agoYou know about F# right? https://dotnet.microsoft.com/en-us/languages/fsharp https://dotnet.microsoft.com/en-us/languages/fsharp https://learn.microsoft.com/en-us/dotnet/fsharp/whats-new/fsharp-9 https://learn.microsoft.com/en-us/dotnet/fsharp/whats-new/fs... Dotnet has compilers for C#, VB and F# and they can all share the same frameworks and libraries. C# is the most popular.
- sedatk 2y agoYou still need to have a class to put your functions in, but they can act only as a namespace, like `Math.DivRem()`. C# has been receiving many functional features over the years including pattern matching, composable data processing (Linq), tuples, and immutable data types. I'm looking forward to a good implementation of discriminated unions now.