编程语言与软件工程2015cs.kent.ac.uk编辑精选
函数式编程为何重要
Why functional programming matters (1990)
进阶 · 约 60 分钟读完前置知识:基本编程经验、函数式编程概念、递归
导读
这篇 1990 年的经典论文(John Hughes)探讨函数式编程为何重要,核心论点是高阶函数和惰性求值提供了新的模块化“胶水”,让程序更易组合。文中以 minimax 算法为例说明,惰性求值可把剪枝等优化实现为独立函数接入,而无需修改生成博弈树的原函数。
HN 关注点:这是 HN 上反复转载的经典重读,讨论焦点既包括惰性求值带来的模块化示例,也包括对 FP 生产力、正确性和模块化提升主张是否有实证支持的质疑。
后来怎么样
成为函数式编程的经典倡导文献,被广泛用于教学和入门阅读,并影响了后来关于高阶函数、惰性求值与模块化的讨论。
HN 评论精选
这几条评论里:支持 1 质疑 2 补充 1
支持惰性求值让剪枝等优化可作为独立函数插入,无需改动原函数,是模块化的关键示例。
几天前终于读了这篇论文。虽然我以为自己已经理解高阶函数和惰性求值,并在日常编程中使用它们,这篇论文仍然很有启发性。以前我没考虑到惰性求值对构建模块化代码有多大帮助。论文最后一节实现 minimax 算法是很好的例子:evaluate 最初只是由几个函数组成的简单链条,遍历所有可能棋局构成的树;随后对它做一系列改进(例如剪枝,让算法能处理无限树,或忽略无法带来有利走法的分支)。妙处在于,借助惰性求值,这些改进可以实现为独立函数,直接“插”进链条,而不必修改原函数。例如,生成整棵博弈树的原函数无需改动就能实现剪枝。我强烈推荐给那些想知道“函数式编程到底为什么值得这么大惊小怪”的人;它既易懂,又充满解决实际具体问题的漂亮代码示例。读完后回到日常工作中的命令式编程世界,我有点难过。
epidemian查看英文原文
Finally read this paper a couple of days ago. Even though i thought i already understood the concepts of higher order functions and laziness, and had used them on my every-day programming, the paper was still quite enlightening. One of the things i hadn't considered before is how much laziness can help to build modular code. The last section in the paper, about implementing the minimax algorithm, is a great example of this. The `evaluate` function is first naively defined as a simple chain of a couple of functions that iterate the tree of all possible game positions. Then a series of improvements are applied to it (e.g. pruning the tree to allow the algorithm to work on infinite trees, or ignoring branches that cannot yield favourable moves), but what's really nice is that thanks to lazy evaluation these improvements can be implemented as independent functions that are just "plugged in" the chain, without having to modify the original functions. For example, the original function that generates the whole game tree doesn't need to be changed to implement pruning. I'd really recommend the paper to anyone who might be wondering "why all this fuss about functional programming?". It's not only very accessible, but also full of beautiful code examples solving very practical and concrete problems. I personally felt a bit sad having to "back" to the imperative programming world in my every-day job after reading it.
质疑质疑 FP 倡导者关于生产力、正确性和模块化大幅提升的说法是否已有研究支持。
这篇论文写于25年前;有没有研究已经证实 Hughes 和其他 FP 倡导者关于生产力、正确性和模块化大幅提升的夸张主张?
thr0wawayhn查看英文原文
This paper was written 25 years ago; have any studies yet justified the extravagant claims made by Hughes and other FP advocates of substantial increases in productivity, correctness, and modularity?
质疑肯定其对模块化需要多种“胶水”的判断,但批评论文只给出两种胶水,主张胶水应可由用户定义。
这篇文章有点奇怪,部分内容很精彩,其他部分就没那么好。关于我们为什么需要模块化、以及这意味着需要新的多种“胶水”的分析非常准确——注意是复数。但接下来他只给出了恰好两种胶水,刚好是复数成立的最小 N。我认为他说得对:我们需要很多种不同的胶水,这意味着胶水必须可由用户定义。而“胶水”是什么?就是架构连接件。并附上“Why Architecture Oriented Programming Matters”一文链接。
mpweiher查看英文原文
This is an odd article, brilliant in parts, somewhat less so elsewhere. The analysis of why we need modularity and that this means we need new kinds (plural) of "glue" is spot on. Note the plural. But then he goes on to present exactly two kinds of glue, so the smallest N for which the plural is justifiable. I contend that he was richt that we need a lots of different kinds of glue, which means that the glue must be user-definable. And what is "glue"? Well, architectural connectors, that's what. Why Architecture Oriented Programming Matters https://blog.metaobject.com/2019/02/why-architecture-oriented-programming.html
补充推荐用 F# 做企业业务应用的视频,认为它绕开抽象数学、直观展示 FP 的现实简单性。
如果想看一个真正让人开眼界的视频,可以看看“Domain Modeling Made Functional”。它把函数式编程应用到普通的企业业务应用(用 F#)。作者论证它为什么简单得多,并用案例走了一遍流程,很难不被说服。它抛弃了许多 FP 演讲里高深疯狂的数学,只展示它作为解决现实问题的一种更简单技术。链接:https://www.youtube.com/watch?v=Up7LcbGZFuo&feature=youtu.be&t=508(建议 1.25 倍速)。它令人印象深刻,也让人奇怪为什么更多推广 FP 的人不展示其切实好处和简单性,而通常用理论/抽象方式呈现。它也是很好的领域驱动设计和数据建模入门,不论你用什么语言。
BoiledCabbage查看英文原文
If anyone is looking for a really eye-opening video take a look at that this. "Domain Modeling Made Functional" It's applying Functional Programming to plain old Enterprise line of business apps in F#. The author argues why it's so much simpler, and simply walks through an example with cases. It's hard not to be persuaded. It leaves behind all of the lofty crazy maths you see in a lot of presentations of FP, and just shows how it's a simpler technique to solve real world problems. Domain Modeling Made Functional - https://www.youtube.com/watch?v=Up7LcbGZFuo&feature=youtu.be&t=508 (Watch on 1.25x speed) It's really impressive, and also surprising why more people promoting FP don't show it's tangible benefits and simplicity vs. the theoretical/abstract way it's usually presented. It's also a great introduction to 'Domain Driven Design' and data modeling regardless of the language you use.
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2015Hacker News 讨论帖113 分 · 139 评
- 2019Hacker News 讨论帖102 分 · 103 评
- 2024Hacker News 讨论帖27 分 · 5 评
同领域还值得读
Google 的软件工程(2017)
Software Engineering at Google (2017)
介绍了 Google 的软件工程实践,包括其单一代码库(monorepo)、几乎全部开发在主干进行而非分支、代码审查、构建系统 Blaze、协议缓冲区等工具与流程,并讨论了频繁重…
编程语言与软件工程2017 · 1,127 分 · 465 评 · 引用 15入门 · 约 45 分钟编辑精选Peter Naur:编程作为理论构建 (1985)
Peter Naur – Programming as Theory Building (1985)
Peter Naur 1985 年的经典论文《Programming as Theory Building》提出:编程的本质不是写代码或文档,而是在程序员头脑中构建对程序及其运行…
编程语言与软件工程2016 · 629 分 · 74 评入门 · 约 45 分钟编辑精选SciPy 1.0:Python 科学计算的基础算法
SciPy 1.0: fundamental algorithms for scientific computing in Python
这篇发表于 Nature Methods 的论文介绍了 SciPy 1.0——Python 科学计算生态的基石库,涵盖其核心算法模块(优化、积分、插值、线性代数等)、软件架构与社…
编程语言与软件工程2020 · 387 分 · 98 评入门 · 约 45 分钟编辑精选Lisp 的历史(1979)
History of Lisp (1979)
这是 Lisp 发明者 John McCarthy 于 1979 年为 HOPL(编程语言史)会议撰写的回顾文章,讲述 Lisp 的起源、设计动机与早期演进,文中也涉及 if 表…
编程语言与软件工程2018 · 352 分 · 44 评入门 · 约 45 分钟编辑精选使用 NumPy 进行数组编程
Array Programming with NumPy
这篇 Nature 文章介绍 NumPy 的数组编程模型及其在科学计算中的核心作用:以 ndarray 为中心,通过向量化操作让 Python 高效处理多维数组。
编程语言与软件工程2020 · 318 分 · 134 评入门 · 约 40 分钟编辑精选