Foreword

People often ask, “What can F# do that C# cannot?” In this book, you will discover much of what F# can do! You will see familiar things such as object programming and design patterns. Further, you will also see powerful new things like pattern matching, piping, first-class events, object expressions, options, tuples, records, discriminated unions, active patterns, agents, computation expressions and, perhaps most distinctively, type providers.

However, we also need to ask the other question: “What can C# do that F# cannot?” There is one important part to this answer that I will focus on here: C# can cause NullReferenceExceptions. “What?” I hear you ask. “Does F# not have nulls?” Right! Perhaps the most important thing the C# programmer needs to know about F# is that F# does not use nulls in routine programming.

Let’s look at some evidence. People using F# at a major UK energy company did a study of two similar ETL (Extract, Transform, Load) applications.[1] Broadly speaking, the applications were in the same zone in terms of functionality or, if anything, the F# application implemented more features. The F# project had a very low bug rate, and its code was 26 times smaller. The size difference is not only the result of language differences; there are also differences in design methodology. The C# project is characterized by the inappropriate overuse of elaborate object abstractions often seen in Java projects—for example, elaborate and unnecessary class hierarchies.

Interestingly, the comparison records that the C# project had 3036 explicit null checks, where a functionally similar F# project had 27, a reduction of 112 times in the total number of null checks. The other statistics in the comparison shown are also compelling, particularly the “defects since go live”: the F# code had zero defects since “go live,” and the C# code had “too many.” These are not unrelated: nulls cause defects. In my opinion, the lack of nulls in routine coding alone makes it worth switching your programming teams to F# where possible.

In this book, you will learn many wonderful things about F#. But don’t lose sight of the big picture: F# is about writing accurate, correct, efficient, interoperable code that gets deployed on time in enterprise scenarios. It does this partly by removing the most pernicious of evils: nulls. If you and your team embrace it, then, all else being equal, your life will be simpler, happy, and more productive.

—Don Syme

F# Community Contributor

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset