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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Can I do FP in my language?

22 点作者 spinningarrow将近 8 年前

5 条评论

randcraw将近 8 年前
I&#x27;m very tempted to explore a coding style in C and C++ using a more functional idiom. I think both languages could benefit greatly if made more transparently &#x27;intensional&#x27; -- more restricted use of in:out function arguments, explicit return variables, minimal pointer arithmetic, more explicit pointer expressions, etc.<p>Has anyone attempted to devise a FP-style guide for non-FP languages? It could be fun to reimagine their now-antiquated idioms spoken in a more intuitive and&#x2F;or legible accent.
评论 #14936552 未加载
gaius将近 8 年前
The answer is &quot;not if you don&#x27;t have first-class functions&quot; in your language.
评论 #14936639 未加载
评论 #14936431 未加载
whipoodle将近 8 年前
&gt; People say they&#x27;re doing FP in JavaScript. What they mean is they sprinkle reduce and map around and they use some pure functions. There&#x27;s a lot of value in that. But otherwise their code is procedural. They have not learned the paradigm, only the features.<p>Yeah, but that&#x27;s probably okay. I feel like there&#x27;s a strong implication here that following the paradigm has inherent value but I&#x27;m not sure why I should think that&#x27;s the case.<p>Basically, I agree with the claim above that &quot;there&#x27;s a lot of value in that.&quot; :)
评论 #14936651 未加载
crimsonalucard将近 8 年前
This article is describing something that is very true but in the end it doesn&#x27;t teach you how to do FP in an otherwise imperative language. This is surprising as it&#x27;s just one single devastatingly simple rule you need to follow in order to do functional programming:<p>After you declare and assign a value to a variable NEVER change it again. That&#x27;s it. Immutability. Almost every other functional programming pattern flows naturally from this restriction.<p>People already know the definition of functional programming and that is a functional program is a program that consists of a single expression and that the complexity of this single expression arises from the fact that this expression is the composition of other smaller functions...<p>What they don&#x27;t know is that if you take an imperative program and make every variable immutable and construct your program following this restriction the final result will be identical to a functional program! The two concepts are isomorphic!<p>Try it if you don&#x27;t believe me.
评论 #14936948 未加载
bradknowles将近 8 年前
FP? Floating Point?<p>I should hope you can do floating point math in just about any language.<p>Yeesh.<p>;)