5 ms·
I left OOP when I left Ruby back in 2015. I won't be going back to OOP ever. I use Elixir now. How much C# is functional these days? I know linq had the beginn
by sergiotapia 5y ago
I left OOP when I left Ruby back in 2015. I won't be going back to OOP ever. I use Elixir now.
How much C# is functional these days? I know linq had the beginnings of it waaaay back in 2010 but do you see a shift in more c# devs going functional instead of OOP? Or is it just another JavaEnterpriseFactoryFactory.cs
- HideousKojima 5y agoThey added record classes (amd record structs) a year or two ago. Discriminated unions are one of the top requested features and they keep hinting that they might make it into the next version but it keeps getting pushed back.
- zamalek 5y agoThey want to implement discriminated unions on the heap. I'm excited for the code clarity, but it falls very short of the performance concern raised by an ancestor comment. That's the OOP trade-off. We're also stuck with structured exception handling, so we'll have none of that Rust Result<T>, or Go tuple, goodness.
- phillipcarter 5y agoC# has tuples that are stack allocated
- Smaug123 5y agoF# allows you to put DUs on the stack, with `[<Stack>]`, for what it's worth.
- Smaug123 5y ago(By this I meant `[<Struct>]`, of course.)
- DeathArrow 5y ago>They want to implement discriminated unions on the heap. I'm excited for the code clarity, but it falls very short of the performance concern raised by an ancestor comment. That's the OOP trade-off. That isn't also the case with Haskell, OCaml and F#? IMO, if you care about performance you go procedural and watch how your data is aligned and how many allocations you do. Functional programming kind of requires to use immutable data structures, so you end up making copies and that will impact performance. I don't think you can have both highly performant and expressive code.
- zamalek 5y agoIf you look at great C# (e.g. aspnetcore source), you'll see that it's heavily OOP - that is definitely the idiomatic approach. I think the main problem with functional .net it that all function types are nominal. Functional C# can get really verbose because of that.
- d3nj4l 5y agoC# is fundamentally OO, so while you can write some pretty functional code in C#, you can't get away without touching OO.
- DeathArrow 5y agoIf you call libraries and frameworks, than yes. But you can use only static classes as code modules with static methods and only use regular classes for data. If you don't make use of encapsulation, inheritance and polymorphism, there isn't much OOP. Nobody forces you to use builders, factories, singletons and what not.
- int_19h 5y agoOO and functional are orthogonal, and C# has both. Definitely more of the former, but it's catching up on the latter - records, immutability, pattern matching etc.
- partomniscient 5y agoIn .Net the F# language is specifically targeted at functional programming. If thats your interest, you're probably better checking that out over what C# supports. https://docs.microsoft.com/en-us/dotnet/fsharp/what-is-fsharp https://docs.microsoft.com/en-us/dotnet/fsharp/what-is-fshar...
- CharlieDigital 5y agoIf you're curious, a small repo that highlights some of the functional features in C# and compares it to JavaScript and TypeScript: https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-6-0-preview-4-performance-edition/ https://devblogs.microsoft.com/dotnet/announcing-entity-fram... One of the best functional features in C# is probably pattern matching: https://timdeschryver.dev/blog/pattern-matching-examples-in-csharp#tuple-patterns https://timdeschryver.dev/blog/pattern-matching-examples-in-...
- DeathArrow 5y ago>I left OOP when I left Ruby back in 2015. I won't be going back to OOP ever. I use Elixir now. Lucky you! But most of us, poor folks, are getting paid to write software in an OOP language. The huge majority of the most used programming laguages, C aside, are OOP. >How much C# is functional these days? I know linq had the beginnings of it waaaay back in 2010 but do you see a shift in more c# devs going functional instead of OOP? Or is it just another JavaEnterpriseFactoryFactory.cs You can write pretty functional code with LINQ, pattern matching, records. Discriminated unions will be also added in the future. In the last two projects I was working on, people mostly uses procedural programming. Where you could find some design patterns it was mostly juniors wanting to show off.