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.

Functional Programming using JavaScript

199 pointsby openmazeover 10 years ago

17 comments

leeoniyaover 10 years ago
finally, a slide deck that uses `history.replaceState` instead of `history.pushState`. no more having to hit &quot;back&quot; 90 times to exit the deck. how the latter ever became a pattern is beyond me.<p>[EDIT] it probably became a pattern because of browsers that didnt implement the history API, so all hashchange events were pushed onto the history stack.
评论 #8653212 未加载
评论 #8653314 未加载
评论 #8653652 未加载
评论 #8654453 未加载
lelfover 10 years ago
For those you want to learn the functional programming I&#x27;d suggest to immedeately commence looking at Ocaml&#x2F;Haskell instead to see the real big picture. Because it&#x27;s of course adorable that you can write <i>map</i> and <i>compose</i> in JS (it&#x27;s 2014, it can do it everywhere), but FP = many more serious things.
评论 #8654623 未加载
评论 #8653791 未加载
评论 #8654556 未加载
评论 #8653995 未加载
评论 #8653794 未加载
评论 #8654212 未加载
评论 #8655038 未加载
评论 #8653202 未加载
sramsayover 10 years ago
I&#x27;m a huge fan of lo-dash, but might switch to Ramda. Here&#x27;s a rundown:<p><a href="http://bahmutov.calepin.co/lodash-to-ramda-example.html" rel="nofollow">http:&#x2F;&#x2F;bahmutov.calepin.co&#x2F;lodash-to-ramda-example.html</a>
idlewanover 10 years ago
The author is misrepresenting imperative code [0]. Instead of the 42 lines of code he thinks is imperative, but really is already functional-compatible, this is what I would write:<p><pre><code> var getIncompleteTaskSummariesForMember_imperative = function(memberName) { return fetchData().then(function(data) { var tasks = data.tasks; var results = []; for (var i = 0; i &lt; tasks.length; i++) { var task = tasks[i]; if (task.member == memberName &amp;&amp; !task.complete) { results.push({ id: task.id, dueDate: task.dueDate, title: task.title, priority: task.priority }) } } results.sort(function(first, second) { return first.dueDate - second.dueDate; }); return results; }); } </code></pre> Still longer than the 10 lines of functional code, but a much more fair comparison.<p>[0]: <a href="http://scott.sauyet.com/Javascript/Talk/2014/01/FuncProgTalk/#slide-123" rel="nofollow">http:&#x2F;&#x2F;scott.sauyet.com&#x2F;Javascript&#x2F;Talk&#x2F;2014&#x2F;01&#x2F;FuncProgTalk...</a>
评论 #8657318 未加载
swahover 10 years ago
There is also @fogus&#x27; book: <a href="http://shop.oreilly.com/product/0636920028857.do" rel="nofollow">http:&#x2F;&#x2F;shop.oreilly.com&#x2F;product&#x2F;0636920028857.do</a><p>I haven&#x27;t read it yet.
评论 #8652867 未加载
评论 #8654367 未加载
roneeshover 10 years ago
This is a really nice presentation that introduces a lot of concepts well and also helps a person conceptually understand how functional programming fits in to the larger programming world.<p>Book mark it and share it.
评论 #8653240 未加载
bodylossover 10 years ago
Intrestingly it seems that the functional version he proposed is much faster than the OO version. <a href="http://jsperf.com/oop-vs-ramda" rel="nofollow">http:&#x2F;&#x2F;jsperf.com&#x2F;oop-vs-ramda</a>
评论 #8653724 未加载
评论 #8656746 未加载
seomisover 10 years ago
I dislike these expositions on the &quot;differences&quot; between object-oriented and functional programming. The two concepts are not directly commensurable, and one can have objects with referentially transparent methods, to be used in a declarative style.
评论 #8655262 未加载
atrilumenover 10 years ago
I believe this is the author of Ramda, yes?<p>I can&#x27;t find the talk, anybody got a link?<p>(Ramda is pretty bad ass.) <a href="http://ramda.github.io/ramdocs/docs/" rel="nofollow">http:&#x2F;&#x2F;ramda.github.io&#x2F;ramdocs&#x2F;docs&#x2F;</a>
评论 #8653761 未加载
评论 #8653774 未加载
killtheliterateover 10 years ago
I put together a similar talk last summer: <a href="http://thedrearlight.com/functional-js-wut" rel="nofollow">http:&#x2F;&#x2F;thedrearlight.com&#x2F;functional-js-wut</a> unfortunately, don&#x27;t have the vid either, but the slides might be complementary to the ones linked by the OP.<p>--edit It&#x27;s formatted kinda weird, where both up&#x2F;down and left&#x2F;right arrows navigate through the different sections.
评论 #8653843 未加载
bahmutovover 10 years ago
Trying to ride the wave: I have written about functional programming in javascript, see blog posts <a href="http://bahmutov.calepin.co/tag/functional.html" rel="nofollow">http:&#x2F;&#x2F;bahmutov.calepin.co&#x2F;tag&#x2F;functional.html</a> - Ramda is great!
评论 #8654321 未加载
inglorover 10 years ago
His functional example in Bluebird and some ES6 (traceur) just becomes:<p>``` return fetchData().get(&quot;tasks&quot;).filter(x =&gt; x.member === memberName).filter(x =&gt; !x.complete).map(x =&gt; {x.id, x.dueDate, x.title, x.priority}).call(&#x27;sort&#x27;); ```
facorreiaover 10 years ago
Bravo for promoting functional programming and showing how it can be done in JavaScript. One issue concerns me, though: using strings to reference attributes. This makes static checking tools much less useful and can lead to difficult to find errors due to refactoring and typos.
评论 #8654061 未加载
评论 #8653533 未加载
serve_yayover 10 years ago
These slides are very difficult to read on a touch device.
评论 #8654259 未加载
ktgover 10 years ago
See also fn.js (Functional JavaScript Library)| <a href="https://bitbucket.org/ktg/fn" rel="nofollow">https:&#x2F;&#x2F;bitbucket.org&#x2F;ktg&#x2F;fn</a>
debacleover 10 years ago
I assume these slides are from a talk?
评论 #8652642 未加载
评论 #8653849 未加载
areskiover 10 years ago
Can we find the talk somewhere?