Stylish F# 6: Crafting Elegant Functional Code for .NET 6. 2nd Edition
Download Full Version of the eBook "Stylish F# 6: Crafting Elegant Functional Code for .NET 6. 2nd Edition"
Download - Stylish F# 6: Crafting Elegant Functional Code for .NET 6. 2nd Edition by Kit Eason - PDF, ePUB
There are three distinct philosophies which you can apply to computer programming. You can think of programming as a science, where the measure of progress is how well you discover and reflect fundamental mathematical concepts in your code. You can think of it as a discipline, where you seek to establish and follow rules about how code should be written and organized. Or, best of all, you can think of it as a craft, where, yes, you apply some of the science and some of the discipline; but you leaven those with a generous helping of human creativity. To do this successfully, you need a fair bit of experience, because crafting something is an inherently intuitive process. This book aims to get you to a level where you can craft code confidently. It does this by distilling and passing on my own experience of writing F# systems in numerous different industries over the past ten years.
Before you start this book, you’ll need at least some knowledge of F# syntax and concepts. Maybe you’ve read some of the wide range of beginner material that’s available, and probably you’ll have written at least a few simple F# programs yourself. You may well have deeper experience of other languages, such as C# or Python. That said, I have framed the book so that C# knowledge is not a hard prerequisite: I learned F# before I learned C#, and if I can do it, so can you! Also you definitely don’t need any background in computer science or functional programming. I don’t have even a trace of formal education in either of these areas.
So what’s between the covers? In Chapter 1, I’ll establish some principles which will help us decide whether we are coding well and say a little bit about why coding stylishly is important. In Chapter 2, we’ll pick up the basic tools of our craft and learn to chisel out elegant and reliable functions. In Chapter 3, we’ll tackle the thorny issue of missing data, learning some effective techniques for writing dependable code when certain values might not be available. In Chapter 4, we’ll pick up some more powerful crafting tools, the so-called collection functions, and explore how you can use them to achieve a surprising amount with very little code. In Chapter 5, we’ll delve into the strange world of immutability: how you can write programs which achieve a result without explicitly changing anything. In Chapter 6, we’ll look at pattern matching, a concept you may have looked at a little when you learned F# syntax, but which is surprisingly pervasive and powerful in quality F# code. In Chapter 7, we’ll explore record types, F#’s go-to structure for storing groups of labeled values. In Chapter 8, we’ll cover some ground which might already be familiar to C# developers: object-oriented classes. In Chapter 9, we’ll return to the topic of F# functions and explore what it means for a function to also be a first-class value. In Chapter 10, we’ll tame the apparent complexity of asynchronous and parallel programming: it needn’t be as hard as you think! In Chapter 11, we’ll look at Railway Oriented Programming, an interesting metaphor you can use to help you think about processing pipelines. In Chapter 12, we’ll investigate performance: Can you really write code which is both elegant and fast? In Chapter 13, we’ll establish some useful techniques for laying out your code and naming items to maximize readability. In Chapter 14, I’ll briefly reiterate what we’ve learned.
As this book is primarily about the language, you’ll find relatively few references to other libraries. Of course, to build substantial systems, you’ll almost always want to pull in NuGet packages for requirements such as unit testing, serialization, web serving, and so forth. But these libraries constitute a large and fast-changing landscape, so I’ve chosen to pare things down to the F# essentials for this book. For the same reason, I hardly mention graphical user interface or web development. Since the first edition of this book, F# has become much more widely used in these areas, but this has been via innovations in the surrounding ecosystem (notably the Fable transpiler), whereas in these pages, I want to concentrate on the F# language itself.
This focus also means that most of the code examples can be typed in and run as cells in a .NET Interactive notebook. They are provided in notebook form in the downloadable code samples. In the small number of cases where you need to write a compilable program, I take you through the process in the text alongside the example. These non-notebook examples are also provided in the downloadable code but in “project” form so that you can open and build them in Visual Studio Code (with the Ionide extension), Visual Studio, or JetBrains Rider.
I very much hope you enjoy sharing my F# experience as much as I enjoyed acquiring it. Don’t forget to have fun!
- CC BY-NC-SA 3.0 PH
- The author's reference is not required