TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Introduction to Functional Programming in JavaScript (Part 1)

44 pointsby bepitulazalmost 9 years ago

5 comments

Noseshinealmost 9 years ago
This reminds me of a blog post (about currying specifically) from an ardent FP proponent that I picked up on HN not long ago, where he back-pedals (his own word) from a much-shared pro-currying in JS article:<p><a href="https:&#x2F;&#x2F;hughfdjackson.com&#x2F;javascript&#x2F;does-curry-help&#x2F;?utm_source=ESnextNews.com&amp;utm_medium=Weekly%20Newsletter&amp;utm_campaign=Week%206" rel="nofollow">https:&#x2F;&#x2F;hughfdjackson.com&#x2F;javascript&#x2F;does-curry-help&#x2F;?utm_so...</a><p>On a personal note, immutability is fine, but doing it in Javascript comes at a cost and it always feels like I&#x27;m fighting the system (have to deep-copy objects and possibly even `Object.freeze()` objects, space-saving write-on-copy needs to be done by myself, no pattern-matching). So I only do it when I&#x27;m sure it is useful. Similar with some other FP concepts that feel natural in &quot;real&quot; FP languages.<p>Also, very few of the functions that cause me any headaches benefit from being pure (in a way that would help me), because my problem is with the consistency and state of the data in (shared) storage. I rarely have issues within the app itself, so &quot;purity&quot; there does not help me all that much in my very I&#x2F;O heavy applications. It seems much more suited for data processing.
评论 #12025895 未加载
dunkelheitalmost 9 years ago
The functional boss micromanages you too, just differently than the imperative boss. The functional boss depicted in the article should really be called the declarative boss.<p>Notice how strange his or her requests are:<p>&quot;Schedule a meeting whenever you feel it is necessary&quot; - what if I feel that surfing facebook is more necessary?<p>&quot;...after you get 3 sales leads by the end of the week&quot; - what if I won&#x27;t be able to get 3 leads by the end of the week? What is more important, getting 3 leads or getting something by the end of the week? I don&#x27;t know. Maybe a Sufficiently Smart Employee will be able to figure it out, but he or she is not yet hired.<p>In the meantime the imperative boss gets a steady stream of leads. And the declarative boss goes out of business after some time.
评论 #12025959 未加载
kowdermeisteralmost 9 years ago
&gt; Imperative programming is a programming paradigm that uses a sequence of statements to reach a certain goal. It focuses on how to perform actions to achieve the expected result.<p>But, but, but... I live my life like that. I focus on the next action to achieve my goal.<p>The two examples remind me a bad TV shop advert starting with the black and white trash old way of doing things.<p>The problem with these articles is that they are often biased towards one side which is often FP, because impreative programming is not sexy.<p>I&#x27;m not saying that FP is bad or inferior :) It just has its places and I still have to read an article which clearly states good use cases for FP rather then selling it me as a religion.
评论 #12025918 未加载
sjclemmyalmost 9 years ago
maybe I&#x27;m wrong but the last example of pureFunction mutates and returns one of its arguments. That&#x27;s not a pure function.
评论 #12025602 未加载
评论 #12028909 未加载
评论 #12025600 未加载
评论 #12025538 未加载
dema_gurualmost 9 years ago
Cool