

Continuation-passing style in JavaScript (2010) - codecurve
http://matt.might.net/articles/by-example-continuation-passing-style/

======
skibz
From the article, itself:

"node.js is a high-performance, server-side platform for JavaScript in which
blocking procedures are banned."

Most of this sentence is correct, excpet for the final part. Blocking
procedures are, in fact, permitted. They are simply discouraged.

~~~
malkia
This is a bit like saying cheaters are discouraged at casinos. In fact they
are banned.

~~~
taternuts
A common example given for this is in node's `fs` class, which provides
synchronous versions of many async calls like `readFile` -> `readFileSync`,

------
jonny_eh
So how is this different than just using callbacks? Looks like you end up in
callback hell. Why not move onto promises?

~~~
myblake
It's just a more organized way to use callbacks, but having spent several
months on a project using CPS in node I will say it certainly helps add order
and remove hellishness.

------
PaulHoule
Neat article, but I'd like, for once, for articles about functional
programming to NOT use the Fibonacci example because in terms of O(N)
performance it is a clear example of malpractice. (i.e. if they were really
math geniuses they'd just use the closed form)

~~~
wwweston
In implementation, yes, you'd (probably) use the closed form. Wouldn't make
for much discussion of various fine points of recursion, though. The purpose
of these examples isn't to discuss efficient mathematical computation, it's to
examine recursion.

For pedagogy Fibonacci and Factorial are used so often because they're easily
defined, often already understood by most with high school algebra under their
belt, and pretty much the archetypical recurrence relations. Not a bad place
to start exploring recursion.

If you want people to move on, you're probably going to need to provide a
better starting place for pedagogical purposes.

~~~
PaulHoule
Just a different one.

There are a lot of reasons why different programming communities don't listen
to each other, and I find the fibonacci example to be a "bad smell".

------
bcg1
FWIW, GNU Guile lets you use "native" call/cc in its (broken?) JavaScript
implementation.

[http://wingolog.org/archives/2009/02/25/callcc-and-
ecmascrip...](http://wingolog.org/archives/2009/02/25/callcc-and-ecmascript)

