News for hackers. Stuff that matters.
Re:Node 8.3.0 released by jnbiche on Thursday August 10, 2017 @10:13AM (#14979860)
Still disappointed that Node has backed out of optimized tailcalls (edit: should have written proper tail calls here, since that's what the past 3 now specs have called for, ES5, ES6, and ES2017). I think it's the only part they haven't implemented.

I think a lot of the pushback I'm seeing against TCO comes from traditional programmers who don't like functional programming and who think that recursion shouldn't play any role in production software. I get that there are also some who have legitimate implementation concerns, but the reflexive pushback TCO gets from a lot of the V8 maintainers compared to any other new ES6 feature seems telling to me (correct me if I'm wrong here).

What they don't understand is that JavaScript programmers are rapidly moving toward functional programming. Already, there's a heavy functional influence on the React community, probably the dominant frontend framework/library at the moment. Clojurescript and Elm have had an outsize influence on the JavaScript community, and I see more and more programmers using functional paradigms in their everyday code (particularly maps, filters, and reductions). I know we'd see much more recursion if it were technically feasible.

Edit: Absolutely right, my critics. I brain farted on this one. It's not Node, it's V8. I did refer to this in the second paragraph, but stupidly blamed Node for it in the first paragraph.

Edit 2: As I said, I shouldn't have singled out Node, particularly since it's V8 that's making this call. But my criticism was more directed toward most of the JavaScript implementers who seemed to have single-handedly decided that the es6 spec was all cool except for the one part they don't like. And I could accept the criticism that implicit tailcalls are problematic, except they seem opposed to labeled tailcalls as well. I think there are lots of implementers who simply don't believe that recursion has a place in "real" software. I've not heard these exact words from an implementers before, but I've known quite a few senior developers of my generation (40s) who have said this exact thing to me (they also can't seem to get the difference between structural and generative recursion).

Re:Node 8.3.0 released by coldtea on Thursday August 10, 2017 @10:26AM (#14979992)
>Still disappointed that Node has backed out of optimized tailcalls, which is part of the ES6 spec. I think it's the only part they haven't implemented.

Node doesn't implement JS features. V8 does and Node gets updated to newer V8 releases every while. Node doesn't have much say in whats gets to v8.

>I think a lot of the pushback I'm seeing against TCO comes from traditional programmers who don't like functional programming and who think that recursion shouldn't play any role in production software. I get that there are also some who have legitimate implementation concerns, but the reflexive pushback TCO gets from a lot of the V8 maintainers compared to any other new ES6 feature seems telling to me (correct me if I'm wrong here).

You're overthinking this. There is no masterplan and no pushback. Just some issues with the old standard -- v8 has even implemented the feature in initial form (but not enabled):

https://v8project.blogspot.gr/2016/04/es6-es7-and-beyond.htm...

Re:Node 8.3.0 released by jnbiche on Thursday August 10, 2017 @10:41AM (#14980157)
> There is no masterplan and no pushback.

I don't think there's a masterplan or some anti-functional conspiracy, but I do think there's pushback. They implemented the feature behind a flag but from what I've read (can't find the reference now), they are not planning to ever release it.

Re:Node 8.3.0 released by coldtea on Thursday August 10, 2017 @10:56AM (#14980336)
Probably looking for this then: https://github.com/tc39/proposal-ptc-syntax/issues/22

But their pushback is for pragmatic reasons, not because they don't like recursion/tail calls.

Re:Node 8.3.0 released by jnbiche on Thursday August 10, 2017 @11:22AM (#14980603)
> But their pushback is for pragmatic reasons

I saw zero reasons given for the failure to implement in that thread (which I had not seen before), other than a brief mention of stack traces (which is quite solvable with a shadow stack). All I saw were several people (including someone involved with the spec) who were bitterly disappointed about the failure to implement. And I forgot that tail call elimination was introduced back in ES5, and yet only JavaScriptCore has implemented it.

Which again leads me to believe that most implementers believe it's just not worth the trouble to them to implement a key feature for functional programming, regardless of how much the users want it (the feedback in this thread is similar to what i've seen elsewhere).

Re:Node 8.3.0 released by apaprocki on Thursday August 10, 2017 @03:47PM (#14983419)
Re:Node 8.3.0 released by mercer on Thursday August 10, 2017 @03:47PM (#14983427)
Could you elaborate? Based on my experience with functional(-style) programming in Clojure and Elixir, tail calls are important enough that, worst case scenario, they might even warrant their own syntax addition (like with Clojure's recur?).

I might be way out of my depth here though; I couldn't quite grok the discussion in your link. Is there's a way perhaps you could 'ELI5' why it's pragmatic to ignore this issue?

Re:Node 8.3.0 released by coldtea on Friday August 11, 2017 @07:33AM (#14988553)
It's pragmatic because adding proper tail calls in the JS engines is difficult and raises several issues (lost stack frames, memory guarantees, etc.) but we were able to survive 20+ years without having them in JS, so it's not like they are essential.
Re:Node 8.3.0 released by jnbiche on Friday August 11, 2017 @02:16PM (#14992710)
> we were able to survive 20+ years without having them in JS, so it's not like they are essential.

And voila the attitude I was referring to, it comes out. Recursion is pretty damn essential to functional programming, and like it or not that's the way JS is headed.

Re:Node 8.3.0 released by coldtea on Sunday August 13, 2017 @11:29AM (#15003280)
>and like it or not that's the way JS is headed.

Well, like it or not, recursion did not make it to ES6/ES7.

Re:Node 8.3.0 released by jnbiche on Monday August 14, 2017 @08:05AM (#15008058)
It did make it to ES6, but the engines failed to implement the spec.
Re:Node 8.3.0 released by specialist on Thursday August 10, 2017 @11:49AM (#14980883)
Huh. No tailcall optimization? Then I don't understand something and have to recheck.

I just wrote a Redis REPL (wire protocol) parser using recursion. Being so simple, I wasn't worried about stack depth. But while stepping thru with WebStorm's debugger, I noticed the tailcalls were (apparently) being eliminated. An unexpected surprise.

Using nodejs 6.11.1, npm 3.10.10.

Re:Node 8.3.0 released by eric_bullington on Thursday August 10, 2017 @01:04PM (#14981751)
It's behind a flag now, but they're eliminating it, so it will not be released.
Re:Node 8.3.0 released by dvlsg on Thursday August 10, 2017 @12:07PM (#14981057)
Yeah, tail call optimization has been in since node 6, I believe. _Maybe_ behind a v8 flag.

https://bugs.chromium.org/p/v8/issues/detail?id=4698

Re:Node 8.3.0 released by ilkkao on Thursday August 10, 2017 @10:33AM (#14980076)
all engines except Safari's JavaScriptCore seem to have decided that implicit tailcalls optimization wasn't a good idea after all and as far I can see are not planning to enable it.
Re:Node 8.3.0 released by jnbiche on Thursday August 10, 2017 @11:24AM (#14980624)
Yeah, they say that, and yet they don't want explicit tailcalls either.
Re:Node 8.3.0 released by hashseed on Thursday August 10, 2017 @04:56PM (#14984159)
iirc JSC folks are blocking explicit tailcalls on TC39
Re:Node 8.3.0 released by jnbiche on Friday August 11, 2017 @02:23PM (#14992772)
Well, not surprised, because they actually did the work and implemented the spec calling for implicit tailcalls, and then it turned out that the other JS engines were to lazy or biased to implement it themselves (mind, all the other parts of the spec were fine, but the one thing they disagreed with they just didn't implement).

So yeah, I'm sure I'd be pretty pissed if I were the JSC devs, and not so happy about the community turning around and saying now we want explicit tailcalls. And by the way, they're also probably smart enough to see that the V8, SM, and ChakraCore are probably not really going to follow through with explicit tailcalls anymore than they would with implicit ones.

Being explicit won't make the implementation any easier, it will just firewall off any performance issues (note that JSC achieved this with implict tailcalls). And since the other engines having been complaining against how hard tailcalls would be to implement, it's unlikely they'll do it regardless of whether they're implicit or explicit.

Re:Node 8.3.0 released by koolba on Thursday August 10, 2017 @10:20AM (#14979921)
Does V8 handle them? If not how would we expect Node to do so?
Re:Node 8.3.0 released by jnbiche on Thursday August 10, 2017 @11:33AM (#14980711)
You're correct, I updated my post accordingly.