TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Functional Programming Isn’t the Answer

3 点作者 socialdemocrat将近 3 年前

2 条评论

dtagames将近 3 年前
When I worked at IBM, I met John Backus, the inventor of functional programming. I definitely didn&#x27;t get it at the time, but have since become an evangelist.<p>This article makes several good points about FP and why everyone can benefit from having functional techniques in their recipe book.<p>But it&#x27;s missing the key fact that introduces problems, which is that there is really no such thing as functional programming <i>in toto</i> because every program must rely on hidden values and have side effects in order to be useful. So functional, in a way, is a myth that we sustain in order to get the benefits he mentions, which are mostly bulletproofing and debug-ability.<p>In reality, all programs are imperative because the processor is imperative; it does only one thing at a time and in a certain order. Einstein said, &quot;Make things as simple as possible, but no simpler,&quot; and this can be said of functional programming, too. Whenever there is a possibility of eliminating a closure, or using immutable, typed data, or composing functions into each other, we should <i>consider</i> the possibility of refactoring to a more functional style -- but that doesn&#x27;t mean we should just do it. The trade off is that FP is more difficult to write and hides bugs better than imperative code. There are fewer bugs when you&#x27;re done, but it&#x27;s harder to get there.<p>One thing I&#x27;ve started to do in my own code is to declare, in the comments, whether a function is purely functional or if it relies on closures or globals. Having these &quot;flags&quot; at the top of every function shows me places where I might want to refactor to remove some of those potential holes.
socialdemocrat将近 3 年前
Some good points made about the difference between using functional programming in a tasteful manner and treating it as a religion.