有人可以澄清这个Joel On Software报价的意思:(功能程序没有副作用) [英] Can someone clarify what this Joel On Software quote means: (functional programs have no side effects)

查看:101
本文介绍了有人可以澄清这个Joel On Software报价的意思:(功能程序没有副作用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天正在阅读 Joel On Software 并跑过 $ b


$ b编程,你不能发明
MapReduce,这个算法使得
Google可以大规模扩展。
术语Map和Reduce来自Lisp
和函数式编程。回想起来,MapReduce
对于任何人来说都是显而易见的
,他们记得他们的
6.001等价的编程类,纯粹的函数式程序有
没有副作用,因此平凡
可并行化。

当他说功能程序没有副作用时,他是什么意思?这是怎么做出并行化的微不足道的?

让我为你的维基百科

简单地说,一个纯函数是一种只根据给定的参数计算事物的函数并返回一个结果。

在屏幕上写入内容或更改全局变量(或数据成员)是一个副作用。依赖除参数外的其他数据也会使得你的函数不是纯粹的,尽管它不是一个副作用。



写一个纯函数可以更容易并行调用它的许多实例。这主要是因为是纯粹的,你可以肯定它不会影响外部世界,也不依赖外部信息。

I was reading Joel On Software today and ran across this quote:

Without understanding functional programming, you can't invent MapReduce, the algorithm that makes Google so massively scalable. The terms Map and Reduce come from Lisp and functional programming. MapReduce is, in retrospect, obvious to anyone who remembers from their 6.001-equivalent programming class that purely functional programs have no side effects and are thus trivially parallelizable.

What does he mean when he says functional programs have no side effects? And how does this make parallelizing trivial?

解决方案

Let me wikipedia it for you

In brief, a pure function is one that calculate things based only on its given arguments and returns a result.

Writing something to the screen or changing a global variable (or a data member) is a side effect. Relying on data other than that given in an argument also makes your function non-pure although it is not a side effect.

Writing a "pure function" makes it easier to invoke many instances of it in parallel. That's mainly because being pure, you can be sure it doesn't effect the outside world and doesn't rely on outside information.

这篇关于有人可以澄清这个Joel On Software报价的意思:(功能程序没有副作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆