Stylish F# – Crafting Elegant Functional Code for .NET and .NET Core

Stylish F# - Crafting Elegant Functional Code for .NET and .NET Core

There are three distinct philosophies that 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 eight 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 and environments, such as C# and .NET. 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 that 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 that achieve a result without explicity 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 that 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 that 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. This also means that almost all the examples can be typed in and simply run as F# scripts, and they are provided in script 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 alongside the example.

Likewise, you won’t find many references to specific integrated development environments (IDEs) such as Visual Studio, Visual Studio Code, Xamarin Studio, or JetBrains Rider. Any of these can be used to edit and run the examples in this book, and all are available as free editions if you don’t already have something installed. If your IDE doesn’t know about F# “out of the box,” simply search online for “F# getting started” to find setup instructions. The samples should work without change on any platform where F# is installed, except you may need to change some paths where the sample code accesses local files.

I very much hope you enjoy sharing my F# experience as much as I enjoyed acquiring it. Don’t forget to have fun!

Kit Eason

电子书说明:

  • 关于本书的内容介绍、目录、详情等请在 AmazonGoolge Books 等售书网站搜索查看,本站仅展示封面作为参考。
  • 如无特殊说明,本站提供的所有pdf均为文字版(aka True PDF or Digitally Created PDF)。
  • 本站已经列出的所有图书均可以找到。
  • 收到PDF链接之后建议尽快下载或者保存到自己的百度网盘,防止链接过期失效。

免费获取本书PDF

扫描下方二维码添加微信号 bookyage 回复本书编号 19018 即可,我们会尽快(一般24小时之内)将本书PDF文件以百度网盘链接的形式发送给您。

注意:每位用户只能免费获取1本书的pdf,超过1本之后需要以微信转账方式每本支付9.9元人民币代找费用才能继续收到相应的pdf。

如果看不到二维码,请按F5刷新本网页!或者直接添加微信号:bookyage