函數式編程基礎_在收件箱中免費學習函數式編程的基礎

函數式編程基礎

by Preethi Kasireddy

通過Preethi Kasireddy

在收件箱中免費學習函數式編程的基礎 (Learn the fundamentals of functional programming — for free, in your inbox)

If you’re a software developer, you’ve probably noticed a growing trend: software applications keep getting more complicated.

如果您是軟件開發人員,則可能已經注意到了一種不斷增長的趨勢: 軟件應用程序越來越復雜。

It falls on our shoulders as developers to build, test, maintain, and scale these complex systems. To do so, we have to create well-structured code that is easy to understand, write, debug, reuse, and maintain.

當開發人員構建,測試,維護和擴展這些復雜的系統時,它就落在我們肩上。 為此,我們必須創建易于理解,編寫,調試,重用和維護的結構良好的代碼。

But actually writing programs like this requires much more than just practice and patience.

但是實際上編寫這樣的程序不僅僅需要練習和耐心。

In my upcoming course, Learning Functional JavaScript the Right Way, I’ll teach you how to use functional programming to create well-structured code.

在我即將開設的課程“正確學習功能JavaScript”中 我將教你如何使用函數式編程來創建結構良好的代碼。

But before jumping into that course (and I hope you will!), there’s an important prerequisite: building a strong foundation in the underlying principles of functional programming.

但是在進入那門課程之前(我希望您會!),有一個重要的先決條件:在函數式編程基本原理中打下堅實的基礎

So I’ve created a new free email course that will take you on a fun and exploratory journey into understanding some of these core principles. Let’s take a look at what the email course will cover, so you can decide how it fits into your programming education.

因此,我創建了一個新的免費電子郵件課程 ,它將帶您進行有趣的探索性旅程,以了解其中的一些核心原則。 讓我們看一下電子郵件課程的內容,以便您決定如何將其納入您的編程教育中。

什么是函數式編程? (What is functional programming?)

So. What is “functional programming,” exactly?

所以。 到底什么是“函數式編程”?

Functional programming isn’t a framework or a tool, but a way of writing code. In functional programming, we place a major emphasis on writing code using functions as “building blocks.”

函數式編程不是框架或工具,而是一種編寫代碼的方式 。 在函數式編程中,我們主要強調使用函數作為“構建塊”來編寫代碼

Your program is defined in terms of one main function. This main function is defined in terms of other functions, which are in turn defined in terms of still more functions — until at the bottom level the functions are just language primitives like “number” or “string.”

您的程序是根據一項主要功能定義的。 主要功能是根據其他功能定義的,其他功能又定義了其他功能-直到最底層的功能都是諸如“數字”或“字符串”之類的語言原語。

If you’re reading this thinking, “Hmm, but wait? Doesn’t every language use functions to write code?” then good ?. It means you’re paying attention. You’re right — every programming language has functions. But functional programming takes it to a whole ‘nother level ?

如果您正在閱讀這種想法, “嗯,還等什么? 并非每種語言都使用函數編寫代碼嗎?” 那好嗎? 這意味著您正在注意。 您是對的,每種編程語言都有功能。 但是函數式編程將它帶到了一個全新的高度?

To understand what I mean, let’s rewind and start with the basics.Every software program has two things:

為了理解我的意思,讓我們回顧一下基礎知識。每個軟件程序都有兩件事:

  1. Behavior

    行為
  2. Data

    數據

When we’re learning about a programming paradigm — like functional programming — it’s often helpful to consider how the paradigm approaches behavior and data respectively. Behavior, for example, is handled purely using functions in functional programming. Functions are “self contained” pieces of code that accomplish a specific task. It defines a relationship between a set of possible inputs and a set of possible outputs — they usually take in data, process it, and return a result. Once a function is written, it can be used over and over and over again. Data is, well, data. In functional programming, data is immutable — meaning it can’t be changed. Rather than changing data they take in, functions in functional programming take in data as input and produce new values as output. Always. Functions and immutable data are the only two things you need to ever deal with in functional programming. To make it even simpler, functions are treated no differently than data.

當我們學習編程范例(如函數式編程)時,考慮范例如何分別處理行為和數據通常會很有幫助。 例如, 行為僅在函數式編程中使用函數來處理。 函數是完成特定任務的“自包含”代碼段。 它定義了一組可能的輸入和一組可能的輸出之間的關系-它們通常接收數據,對其進行處理并返回結果。 編寫函數后,就可以一次又一次地使用它。 數據就是數據。 在函數式編程中,數據是不可變的,這意味著無法更改。 功能編程中的功能不是更改其接收的數據,而是將數據作為輸入,并產生新的值作為輸出。 總是。 函數和不變數據是函數編程中僅需處理的兩件事。 為了使其更簡單,對函數的對待與對數據的對待沒有區別。

Put another way, functions in functional programming can be passed around as easily as data. You can refer to them from constants and variables, pass them as parameters to other functions, and return them as results from other functions. This is the most important thing to understand when approaching functional programming.

換句話說, 函數式編程中的函數可以像數據一樣容易地傳遞。 您可以從常量變量中引用它們,將它們作為參數傳遞給其他函數,并作為其他函數的結果返回。 在進行函數式編程時,這是最重要的了解。

By treating functions as nothing more special than a piece of data and by only using data that is immutable, we are given a lot more freedom in terms of how we can use functions.

通過將函數視為僅比一條數據更特殊的事物,并且僅使用不可變的數據,就如何使用函數而言,我們將獲得更多的自由。

Namely, it allows us to create small, independent functions that can be reused and combined together to build up increasingly complex logic. We can break any complex problem down into smaller sub-problems, solve them using functions, and finally combine them together to solve the bigger problem. Considering the ever-growing complexity of software applications, this kind of “building-block” approach makes a huge difference in keeping programs simple, modular, and understandable. This is also why developers strive to make their functions as general-purpose as possible, so that they can be combined to solve large, complex problems and reused to speed up development time for subsequent programs.

即,它使我們能夠創建小的獨立功能,這些功能可以重復使用并組合在一起以建立越來越復雜的邏輯。 我們可以將任何復雜的問題分解為較小的子問題,使用函數解決它們,最后將它們組合在一起以解決更大的問題。 考慮到軟件應用程序的日益復雜性,這種“構建塊”方法在使程序保持簡單,模塊化和易于理解方面具有巨大的差異。 這也是開發人員努力使它們的功能盡可能通用的原因,以便可以將它們組合起來解決大而復雜的問題,并可以重用它們以加快后續程序的開發時間。

Ultimately, the reason that functions are so powerful in functional programming is because the functions follow certain core tenets. Those tenets will be the subject of my email course:

最終,功能之所以在功能編程中如此強大是因為這些功能遵循某些核心原則。 這些原則將成為我的電子郵件課程的主題:

  • Functions are pure

    功能純
  • Functions use immutable data

    函數使用不可變數據
  • Functions guarantee referential transparency

    功能保證參照透明
  • Functions are first-class entities

    功能是一流的實體

After that, I’ll briefly touch on how functional programming applies these tenets to encourage us to think carefully about our data and the functions that interact with it.

之后,我將簡要介紹函數式編程如何應用這些原則,以鼓勵我們仔細考慮數據以及與之交互的函數。

By the end, you’ll be able to understand how this approach leads to code that is:

到最后,您將能夠了解這種方法如何導致代碼如下:

  • Easier to understand (that is, “expressive”)

    易于理解(即“表達”)
  • Easier to reuse

    易于重用
  • Easier to test

    更容易測試
  • Easier to maintain

    易于維護
  • Easier to refactor

    易于重構
  • Easier to optimize

    易于優化
  • Easier to reason about

    容易推理

Sound exciting? Come along for the ride!

聽起來令人興奮嗎? 快來兜風吧!

Sign up for the free email course now. Then you’ll receive the first lesson in your inbox within 1–3 days of signing up ?

立即注冊免費的電子郵件課程 。 注冊后的1-3天內,您會在收件箱中收到第一堂課嗎?

翻譯自: https://www.freecodecamp.org/news/learning-the-fundamentals-of-functional-programming-425c9fd901c6/

函數式編程基礎

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/395769.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395769.shtml
英文地址,請注明出處:http://en.pswp.cn/news/395769.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

安卓Java虛擬機大小_虛擬機為安卓流暢度背鍋,是因為關系數十萬程序員飯碗?...

導讀:虛擬機相當于應用程序在不同運行環境中的翻譯。說起谷歌安卓系統的“虛擬機”,很多人愛拿它和蘋果iOS做比較,結果,安卓的很多短腿兒都讓虛擬機背了鍋,比如安卓手機運存容量是iPhone的兩到三倍,流暢度卻…

Redis PHP連接操作

安裝 要在PHP程序中使用Redis,首先需要確保 Redis 的PHP驅動程序和 PHP 安裝設置在機器上。可以查看 PHP教程 教你如何在機器上安裝PHP。現在,讓我們來看看一下如何設置 Redis 的PHP驅動程序。 需要從 github 上資料庫: https://github.com/n…

AppCompatActivity實現全屏的問題

前言:我的 Activity 是繼承 BaseActivity , 而 BaseActivity 繼承 AppCompatActivity 。 BaseActivity 的繼承 /*** 應用程序的基類**/ public class BaseActivity extends AppCompatActivity {}HomeActivity 的繼承 public class HomeActivity extends BaseActivit…

aws cognito_使用AWS Cognito的用戶管理—(1/3)初始設置

aws cognitoby Kangze Huang黃康澤 使用AWS Cognito的用戶管理—(1/3)初始設置 (User Management with AWS Cognito — (1/3) Initial Setup) 完整的AWS Web樣板-教程1A (The Complete AWS Web Boilerplate — Tutorial 1A) Main Table of Contents Click Here主要目錄請點擊這…

java建一個conversion_Scala中的JavaConverters和JavaConversions之間有什么區別?

JavaConversions 提供了一系列隱式方法,可以在Java集合和最接近的相應Scala集合之間進行轉換,反之亦然 . 這是通過創建實現Scala接口的包裝器并將調用轉發到底層Java集合或Java接口,將調用轉發到底層Scala集合來完成的 .JavaConverters 使用p…

flexbox:1.0.0_了解Flexbox:您需要了解的一切

flexbox:1.0.0This article will cover all the fundamental concepts you need to get good with the CSS Flexbox model. It’s a long one, so I hope you’re ready for it.本文將介紹您熟悉CSS Flexbox模型所需的所有基本概念。 這是一個很長的時間,所以希望您…

10.Object類

在JAVA中,所有的類都直接或間接繼承了Java.lang.Object類Object是一個特殊的類,他是所有類的父類,是Java類層中的最高層類。當創建一個類時,他總是在繼承,除非某個類已經指定要從其他類繼承,否則他就是從ja…

RecyclerView的下拉刷新和加載更多 動畫

下拉刷新和加載更多 1、https://github.com/jianghejie/XRecyclerView 2、http://blog.csdn.net/jabony/article/details/44780187 動畫 1、https://github.com/wasabeef/recyclerview-animators

java中顯示動態信息的方法_java里的動態表單技術

最近的一個項目,由于客戶的需求等信息不確定,為了降低以后修改的成本及產品的推廣考慮到動態表單技術,之前也一直在考慮到動態表單技術,畢竟在delphi里已經實現過了,由于我們采用的hibernate的執久層的原故&#xff0c…

Cinder 組件詳解 - 每天5分鐘玩轉 OpenStack(47)

本節我們將詳細講解 Cinder 的各個子服務。 cinder-api cinder-api 是整個 Cinder 組件的門戶,所有 cinder 的請求都首先由 nova-api 處理。cinder-api 向外界暴露若干 HTTP REST API 接口。在 keystone 中我們可以查詢 cinder-api 的 endponits。 客戶端可以將請…

中國移動 全球通、 動感地帶、神州行 的區別

1、全球通 1、主要面向商務人士可以享受機場VIP俱樂部的尊貴、1860專席的高質量服務、個性化賬單、客戶積分獎勵以及大客戶經理貼心服務,更有尊貴資費套餐優惠,但它價格也是最貴的。 2、全球通面對事業成功的人士,進取。 3、全球通&#xff…

java 并發測試main方法_java并發編程test之synchronized測試

synchronized關鍵字可以用于聲明方法,也可以用于聲明代碼塊;package com.test.java;public class SyncTest {public static void main(String[] args) {SynchronizedDemo1 synct1 new SynchronizedDemo1();SynchronizedDemo2 synct new SynchronizedDemo2();SynchronizedDemo…

業余愛好者linux_如何從業余愛好者變成專業開發人員

業余愛好者linuxby Ken Rogers肯羅杰斯(Ken Rogers) 如何從業余愛好者變成專業開發人員 (How to Go From Hobbyist to Professional Developer) A few years ago, I was bouncing back and forth between landscaping jobs and restaurant jobs. I had just left college, and…

RedHat Enterprise Linux 6 配置Xmanager ,實現圖形界面連接

我們經常見到的幾種最為常用的windows下遠程管理Linux服務器的方法,基本上都是利用SecureCRT,或者是PUTTY等客戶端工具通過ssh服務來實現Windows下管理Linux服務器的,這些客戶端工具幾乎不需要什么配置,使用簡單,但是它們都無法啟…

Mac下配置iterm2 支持rz sz命令

轉自:http://blog.csdn.net/citywolf4/article/details/49071679 1.安裝lrzsz,使用brew命令:brew install lrzsz如果找不到lrzsz,使用以下命令更新brew庫:brew update2.下載zmoden腳本在https://github.com/mmastrac/iterm2-zmode…

java中session對象登錄_JavaWeb中Session對象的學習筆記

一、Session簡單介紹在WEB開發中,服務器可以為每個用戶瀏覽器創建一個會話對象(session對象),注意:一個瀏覽器獨占一個session對象(默認情況下)。因此,在需要保存用戶數據時,服務器程序可以把用戶數據寫到用戶瀏覽器獨…

vux flexbox使用_Flexbox用大的,彩色的動畫gif進行解釋

vux flexbox使用Here are three links worth your time:這是三個值得您花費時間的鏈接: How Flexbox works — explained with big, colorful, animated gifs (5 minute read) Flexbox的工作原理-帶有大尺寸,彩色動畫gif動畫( 閱讀5分鐘 ) How to commi…

微信小程序 沒有找到 node_modules 目錄

在學習小程序云開發的時候,遇到一個問題,使用npm i --production 和npm i vant-weapp -S --production之后,在微信開發者工具中并沒有node_modules文件夾 但是在根目錄下生成了一個package-lock.json文件。也就是下載的依賴都已經裝好了&…

關于Unity中UI中的Image節點以及它的Image組件

一、圖片的Inspector面板屬性 Texture Type:一般是選擇sprite(2D and UI) Sprite Mode:一般是選擇Single Packing Tag:打包的標志值,最后打包的時候會把Tag相同的所有小圖打包成一個大圖。不像cocos打包圖集需要用到第三方軟件&am…

Knockoutjs官網翻譯系列(一)

最近馬上要開始一個新項目的研發,作為第一次mvvm應用的嘗試,我決定使用knockoutjs框架。作為學習的開始就從官網的Document翻譯開始吧,這樣會增加印象并加入自己的思考,說是翻譯也并不是純粹的翻譯,會加入自己對知識點的思考以及自…