官术网_书友最值得收藏!

Benefits of using F# over C#

And now on to the language wars!

A common inquiry among seasoned C# developers is, "What is the benefit of using F#? Or to word it differently, why do I need to learn a new language when I can perform the same tasks in the language I already know and love?"

A good analogy is LaTeX versus Microsoft Word. You may have used LaTeX for typesetting. For complicated tasks, Word becomes too complex or even unusable. Marko Pinteric explains why you would want to use LaTeX instead of Word with the following graph:

Complexity and learning curve. Using LaTeX on Windows by Marko Pinteric (www.pinteric.com/miktex.html)

The same applies to F#. Functional programming does have a learning curve but it equips you with the tools needed to go further in algorithmic software development. This eventually leads to the argument of general benefits of functional programming over imperative and object oriented languages.

Using functional programming with F#, one can arguably formulate and design solutions in an easier, more effective manner, especially if these problems pertain to the algorithmic domain. As a functional language, F# facilitates keeping the problem closer to their definition in a concise and terse manner. From the testability perspective, the resulting code becomes less error-prone due to its powerful type system, intuitive recursive representation of algorithms, and built-in immutability. Data structure immutability is especially helpful in the case of multi-threaded scenarios. This is, in essence, due to built-in data type immutability.

The specific F# advantages include the following:

  1. Interoperability with the .NET CLR languages.
  2. Ease of asynchronous programming, intuitive use of async {} expressions.
  3. Full Visual Studio .NET IDE integration with compiler and debugger support.
  4. Suitability for writing domain-specific languages and compilers.
  5. Improved performance, scalability, and reduced maintenance cost due to enhanced testability and terseness.
  6. Language extensibility features such as units of measurements, record types, and language-oriented programming support.

Any functional language in general, and F# in particular, is not a silver bullet and shouldn't be treated as one. For UI centric and other applications of highly stateful nature, C# and other imperative .NET languages are a better fit than a functional programming language. Having said that, if you are a quant, who is writing high frequency trading algorithms in F#, or a rewriting to improve an existing VWAP implementation, you will be delighted to know that you can easily expose the F# functionality using your server-side C# WCF libraries. However, since you can have F# and C# together in one .NET solution, it is easy to combine the benefits of both languages and use as needed.

主站蜘蛛池模板: 平山县| 宁波市| 博罗县| 澜沧| 元朗区| 兴海县| 当雄县| 遂宁市| 秦皇岛市| 二连浩特市| 姜堰市| 平陆县| 治多县| 红桥区| 荆门市| 罗平县| 会昌县| 张家港市| 保德县| 永福县| 涿州市| 晋江市| 独山县| 阳春市| 泾阳县| 曲沃县| 太仓市| 陆丰市| 墨竹工卡县| 廊坊市| 罗定市| 元谋县| 综艺| 红安县| 延长县| 拉孜县| 格尔木市| 屏边| 南充市| 文山县| 台湾省|