F# and C# 's CLR is same then why is F# faster than C#

前端 未结 7 734
失恋的感觉
失恋的感觉 2021-01-18 02:42

I am confused and would appreciate if you enlighten me. F# uses same CLR as C# and underlying code is identical then how can one suggest that a function runs faster when wr

7条回答
  •  别那么骄傲
    2021-01-18 03:04

    There is no reason to switch but I suggest components built to meet the best standards. F# enforces alot of standards, makes real time testing during development simple, and cures issues of mutability, circular dependency, as well as most type checking / null references. C# on the other hand has the majority of developers and tools and can be developed with a functional pattern in mind but not always correct. I'm a C# fan and almost always choose C# but I see many times when F# is what I need most to build cleaner robust code. I guess, I personally prefer to blend the two languages when I can but as mentioned it's more important to work with what your dev team can also maintain and review. In many situations, the dev team will be against it but in some they will be for it because they also want not only to make the code base as strong as possible but learn new things. Just don't waste too much time deciding the correct language, if you're certain F# is best, present it and see if you have a consensus to complete it that way. Keep your project separate, even if they are in the same solution, and use F# when it works best and C# when it works best. F# isn't that hard to learn, but to a purely imperative developer it might look ugly and confusing at first. Just explain it some and I think it gets the ball rolling. Times to consider F# would be in algorithms where you not only want performance but immediate testing of the results. This speeds up dev time and runtime, win win. Others might be models if the models consist of many immutable values. F# works in all areas but for me the UI side is done easier in C# as well as things like ViewModels where logic is slightly different but that's an opinion. You'll be surprised at the gains you get from a sweet combination of the two. Besides, functional programming is getting easier with linq, lambda, and newer C# syntax where C# basically looks functional so your pitch to use F# may not be as tough as it would years ago.
    I didn't cover anything to the max but you get the idea...F# is powerful, use it when it works best and the same for C#. I started with VB.NET but wouldn't recommend it anymore simply because newer tech like .NET Core isn't supporting it. However, there is also a benefit to use it at times... Although be it far less than a benefit of F#. In that regard I just stick to the two primaries C#, F#.

提交回复
热议问题