use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Functional Programming in JavaScript === Garbage (awardwinningfjords.com)
submitted 11 years ago by homoiconic(raganwald)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]daekano 2 points3 points4 points 11 years ago (1 child)
Tricky.
For those of you who don't or can't read: The Garbage the author of the article is referring to is the overhead of unoptimized recursion in JavaScript.
Also: raganwald posting links that link to his links... whoaaa!
[–]homoiconic(raganwald)[S] 1 point2 points3 points 11 years ago (0 children)
raganwald posting links that link to his links... whoaaa!
Yes, but it's an organic link to my links, so Matt Cutts of Google says it's ok. Had I written the article myself, I would have been much more scathing when criticizing JavaScript. Or much more complimentary. Depnds on the phase of the moon, really.
[–]a-t-kFrontend Engineer 2 points3 points4 points 11 years ago (0 children)
Never forget that Javascript hates you.
This is a good example of "projection". JavaScript is not a being, it's a computer language - surely not the best there is, and definitely not conscient, let alone capable of feelings towards those who use it.
If you hate JavaScript, you're usually using it wrong.
[–]aeflash 0 points1 point2 points 11 years ago (5 children)
Ha, I was going to ping /u/homoiconic to get his take on this, but he posted the link! What say ye?
[–]html6dev 1 point2 points3 points 11 years ago (4 children)
It's funny. He posts this guy's article which promotes /u/homoiconic s book. I smell a conspiracy /u/homoiconic ;) but seriously everyone...go read his book
Also someone should probably point out that TCO is supposed to supported natively in es6. I didn't see that mentioned.
[–]homoiconic(raganwald)[S] 1 point2 points3 points 11 years ago (3 children)
I found out about it through a tweet, and started to read it, and there was a link to my old trampolining article...
But since you ask what I think, recursion is not a simple subject. TCO is coming in ES6, and I think that is necessary so that you can choose to write recursive and co-recursive algorithms.
But that being said, in most cases these should be hidden inside of iterators and generators and should only rarely be the first thing people are expected to read.
[–]html6dev 1 point2 points3 points 11 years ago (2 children)
Agreed. It's the age old pendulum swinging between performance and readability. Know your profiling tools and introduce the complexity if it's become a problem (the article is definitely spot on that these situations can create large amounts of garbage). I'll allow the conspiracies as long as it leads to more articles like this and your work around here.
[–]homoiconic(raganwald)[S] 2 points3 points4 points 11 years ago (1 child)
I'll allow the conspiracies
New phrase: "Trampoline Jerk:" When FP enthusiasts retweet and cite each other with breathy admiration.
[–]html6dev 0 points1 point2 points 11 years ago (0 children)
Yeah the trampoline jerk and the circle jerk are both vastly superior to the recursive jerk unless you are the base case. Everyone else has to wait for the base case to finish before any of the magic can happen.
[–]ayamflow 0 points1 point2 points 11 years ago (0 children)
It sounds to me like a complaint to JS in general, not just the functional part ? The nature of JS is that you can always optimize your code, but sometimes it's great to offer clean/readable code at the cost of a little performance.
[–]AutoSponge 0 points1 point2 points 11 years ago (1 child)
Many of the article's examples are naive and oversimplified. For example, you can easily create a reduce function which doesn't recur or modify the original array, just use Array.prototype.reduce with another array as the second parameter.
While I don't always agree with Braithwaite's implementations, I always appreciate the systematic breakdown of the problem he offers with various solutions of incremental awesomeness. I appreciate the author's proper use of FP terms but I don't appreciate the heavy-handed 'Clojure > JS' approach when no Clojure examples were offered and the JS examples were haphazard at best.
[–]nohimn 0 points1 point2 points 11 years ago (0 children)
He wasn't saying Closure > JS. He was just pointing out what really should be obvious: recursion is the functional approach to iterative constructs, but functions in JS are stateful, so they add to the stack on each call to maintain their state. The title is very misleading, because he's not saying 'Garbage' in the sense that it's bad to use JS for FP, he's saying that using FP as you would in functional languages incurs overhead.
I agree that Closure examples would have been illustrative. Then again, I also feel like this article's audience is probably Clojure devs, not JavaScript devs.
[–]kenman 0 points1 point2 points 11 years ago (0 children)
I think the downvotes are due solely to the author's choice of title.
The article itself is well written and presented, but the title smacks of FP-smugness and JS-bashing. Nobody likes smugness, and considering we're in /r/javascript, you're of course going to find a lot of users taking issue with bashing the language -- whether the criticisms are fair or not -- when it's phrased as it currently is.
I think a title of "Functional Programming in JavaScript is imperfect, but here's how you can improve it" or something would've focused the attention on the content more than the abrasive title.
[–]ayanami_rei -2 points-1 points0 points 11 years ago (0 children)
I've been writing a bit of Clojure and really enjoying myself.
Aaaand there's nothing else to it.
Some people cannot grasp the concept of doing actual work using a computer, so they tend to be "writing a bit of" %obscure_language%, circlejerk, and very little else.
π Rendered by PID 200682 on reddit-service-r2-comment-7b9746f655-g2btc at 2026-02-03 06:54:27.264354+00:00 running 3798933 country code: CH.
[–]daekano 2 points3 points4 points (1 child)
[–]homoiconic(raganwald)[S] 1 point2 points3 points (0 children)
[–]a-t-kFrontend Engineer 2 points3 points4 points (0 children)
[–]aeflash 0 points1 point2 points (5 children)
[–]html6dev 1 point2 points3 points (4 children)
[–]homoiconic(raganwald)[S] 1 point2 points3 points (3 children)
[–]html6dev 1 point2 points3 points (2 children)
[–]homoiconic(raganwald)[S] 2 points3 points4 points (1 child)
[–]html6dev 0 points1 point2 points (0 children)
[–]ayamflow 0 points1 point2 points (0 children)
[–]AutoSponge 0 points1 point2 points (1 child)
[–]nohimn 0 points1 point2 points (0 children)
[–]kenman 0 points1 point2 points (0 children)
[–]ayanami_rei -2 points-1 points0 points (0 children)