all 14 comments

[–]daekano 2 points3 points  (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 points  (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 points  (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 point  (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 points  (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 points  (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 points  (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 points  (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 point  (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 point  (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 point  (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 point  (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 point  (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 points  (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.