有必要学习函数式编程吗_学习函数式编程使我的开发人员提高了10倍

有必要学习函数式编程吗

Learning functional programming made me a 10x better developer. It helped me learn how write code that is clean, easy to maintain, and scalable.

学习函数式编程使我的开发人员素质提高了十倍。 它帮助我学习了如何编写干净,易于维护和可扩展的代码。

This is especially important in this day and age where software applications keep getting more complicated. The days of building and maintaining a simple web app are over.

在当今软件应用变得越来越复杂的时代,这一点尤其重要 构建和维护简单的Web应用程序的时代已经结束。

As a developer, the expectations set upon you are higher than ever. It now falls on our shoulders to build, test, maintain, and scale complex applications that impact millions of people daily. This can be especially daunting as a beginner because we’re just getting the hang of writing code that actually works, let alone writing code that is easy to understand, write, debug, reuse, and maintain.

作为开发人员,对您的期望比以往更高。 现在,构建,测试,维护和扩展每天影响数百万人的复杂应用程序,就落在了我们的肩上。 这可能是特别艰巨作为一个初学者,因为我们刚开始写一些实际的工作 ,更别说写代码很容易理解,编写,调试,重复使用和维护代码的窍门。

This is where Functional programming made a difference for me—it helped me learn how to code that is easy to understand, write, debug, reuse, and maintain. As a result, I feel much more confident in my coding abilities.

在这里,函数式编程对我产生了影响-它帮助我学习了如何编写易于理解,编写,调试,重用和维护的代码。 结果,我对自己的编码能力更加自信。

Even if you are not using a functional programming language at work or on your side projects, knowing the basics of functional programming equips you with a powerful set of tools to write better code.

即使您不在工作中或在副项目中使用功能性编程语言,了解功能性编程的基础知识也会为您提供一套功能强大的工具,以编写更好的代码。

In my new e-book, I’ll teach you the basics of functional programming so that you have all the foundational knowledge you need to apply the principles at work, in your next job interview, or on your next side project.

在我的新电子书中 ,我将教您函数式编程的基础知识,以便您掌握在工作中,下一次工作面试中或在下一个副项目中应用这些原理所需的全部基础知识。

The rest of the post will give you a simple explanation of what functional programming is, which you’ll need to know before diving into the e-book. 😎

文章的其余部分将为您简要介绍什么是函数式编程,在深入阅读电子书之前,您需要了解这些内容 。 😎

Let’s get right into it! 😊

让我们开始吧! 😊

什么是函数式编程? (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 (what the program does)

    行为 (程序做什么)

  2. Data (data, is well, 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, in functional programming, is handled purely using functions in functional programming. Functions are “self contained” pieces of code that accomplish a specific task. They define 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, in functional programming, 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? If so, you'll love the new e-book. 🤗

听起来令人兴奋吗? 如果是这样,您会爱上这本新的电子书。 🤗

The e-book will be released on December 13th. You can pre-order the e-book now for just $49! And as special offer to the free FreeCodeCamp community, I am offering $10 off with the discount code "freecodecamp".

电子书将于12月13日发行。 现在只需49美元即可 预订电子书 作为对FreeFreeCamp社区的特别优惠,我提供10美元的折扣,折扣代码为“ freecodecamp ”。

See you in there! 🤓📕✍️

在那里见! 🤓📕✍️

翻译自: https://www.freecodecamp.org/news/learn-the-fundamentals-of-functional-programming/

有必要学习函数式编程吗

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Until recently, the message has been Go and functional programming—don't do it. Functional programming (FP) is a perfect fit for multicore, parallel processing. Go is a concurrency baller (with Goroutines, channels, and so on) and already runs on every available CPU core. FP reduces complexity; simplicity is one of Go's biggest strengths. So, what can FP bring to Go that will actually improve our software applications? Here's what it offers: Composition: FP shows us how to decompose our apps and rebuild them by reusing small building blocks. Monads: Using monads, we are able to safely order our workflows into pipelines of data transformations. Error handling: We can leverage monadic error handling and still maintain compatibility with idiomatic Go code. Performance: Referential transparency is where we can evaluate our function once and then subsequently refer to its pre-computed value. Expressive code: FP allows us to concisely express business intent in our code. We declare what our functions do, without the clutter of error checking after every function call, and without having to follow state changes (pure FP means immutable variables). Simpler code: No shared data means not having to deal with semaphores, locks, race conditions, or deadlocks. Most people have difficulty grasping FP. I did too. And when I got it, I wrote this book. Take this journey with me. We'll see hundreds of illustrations, read easy-to-understand explanations, and implement FP in Go code along the way. I enjoyed coaching soccer. The litmus test I used to determine whether I succeeded as a coach was the answer to this simple question: Did they all register for next season and request me to be their coach? Just like planning practice, I planned each chapter, starting with simple concepts and adding to them. Read this book, then you too will be able to say, I got it.
Learning C++ Functional Programming by Wisnu Anggoro English | 10 Aug. 2017 | ISBN: 1787281973 | ASIN: B06WVD7CVT | 304 Pages | AZW3 | 2.4 MB Key Features Modularize your applications and make them highly reusable and testable Get familiar with complex concepts such as metaprogramming, concurrency, and immutability A highly practical guide to building functional code in C++ filled with lots of examples and real-world use cases Book Description Functional programming allows developers to divide programs into smaller, reusable components that ease the creation, testing, and maintenance of software as a whole. Combined with the power of C++, you can develop robust and scalable applications that fulfill modern day software requirements. This book will help you discover all the C++ 17 features that can be applied to build software in a functional way. The book is divided into three modules—the first introduces the fundamentals of functional programming and how it is supported by modern C++. The second module explains how to efficiently implement C++ features such as pure functions and immutable states to build robust applications. The last module describes how to achieve concurrency and apply design patterns to enhance your application's performance. Here, you will also learn to optimize code using metaprogramming in a functional way. By the end of the book, you will be familiar with the functional approach of programming and will be able to use these techniques on a daily basis. What you will learn Get to know the difference between imperative and functional approaches See the use of first-class functions and pure functions in a functional style Discover various techniques to apply immutable state to avoid side effects Design a recursive algorithm effectively Create faster programs using lazy evaluation Structure code using design patterns to make the design process easier Use concurrency techniques to develop responsive software Learn how to use the C++ Standard Template Library and metaprogramming in a functional way to improve code optimization About the Author Wisnu Anggoro is a Microsoft Certified Professional in C# programming and an experienced C/C++ developer. He has also authored the books Boost.Asio C++ Network Programming - Second Edition and Functional C# by Packt. He has been programming since he was in junior high school, which was about 20 years ago, and started developing computer applications using the BASIC programming language in the MS-DOS environment. He has solid experience in smart card programming, as well as desktop and web application programming, including designing, developing, and supporting the use of applications for SIM Card Operating System Porting, personalization, PC/SC communication, and other smart card applications that require the use of C# and C/C++. He is currently a senior smart card software engineer at CIPTA, an Indonesian company that specializes in innovation and technology for smart cards. He can be reached through his email at [email protected]. Table of Contents Diving into Modern C++ Manipulating functions in functional programming Applying immutable state to the function Recurring method invocation using recursive algorithm Procrastinating the execution process using Lazy Evaluation Optimizing code with Metaprogramming Running parallel execution using Concurrency Creating and debugging application in functional approach

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值