

Keeping sanity in callback hell - flashingpumpkin
http://owns.ch/keeping-sanity-in-callback-hell.html

======
SamReidHughes
If you think that's callback hell, you try doing it in C++.

------
jmah
This is a JS (CoffeeScript) implementation of the Maybe monad.

~~~
njs12345
It'd be interesting to see a JavaScript-like language with syntactic support
for monads (do and friends) - seems like it would enable better abstractions
for a lot of this type of thing.

There's LambdaScript (<https://github.com/valderman/lambdascript>) of course,
but from the README it doesn't look like it's something you want to use at the
moment..

------
moomin
Or use async.js, or step, which already have addressed this issue. They look
nice in coffeescript too.

------
davidw
I think Node, Scala, and company will eat Erlang's lunch. However, looking at
that code makes you realize that the Erlang actor model with an internal
scheduler is pretty nice for a lot of things.

~~~
thesz
I don't think so. Erlang combines powers of Scala and Node and adds some of
its own - selective receive, for example.

~~~
davidw
You don't think what? If it's not clear, I am saying that I think Erlang's
runtime and API are superior to callback spaghetti.

What we may not agree on is whether Node and Scala are going to surpass Erlang
in terms of popularity. I think it's only a matter of time. Those two systems
are based on languages/runtimes that are orders of magnitude more popular than
Erlang and are thus far more accessible. Being far more recent systems, as
well, they also avoid some of the strange warts that Erlang must keep around
because it's widely deployed enough that it can't be easily changed.

~~~
thesz
I don't think that Node or Scala alone will eat Erlang's lunch. Combined -
maybe, but highly unlikely anyway.

By the way, Erlang releases often break backward compatibility. And what are
those warts you mentioned?

~~~
davidw
The syntax is tough for newbies, strings/lists being conflated is ... not so
nice, macros/include files are ugly. Records - ugly! Command line options make
it inconvenient for scripting tasks. Lack of libraries (compare with Scala,
which has access to pretty much all of Java), no code repositories, ala
rubygems. Also: it's more verbose than languages like Ruby, but not as fast,
generally, as things like C or Java, putting it at a bit of an odd place for
me.

They're mostly minor nits, and don't prevent me from liking and using the
language, but I'm skeptical about it ever being more than a niche language.
Yes, obviously other languages have succeeded without having all those things,
that's just the laundry list off the top of my head.

~~~
Xurinos
Interesting nits. In my earlier days, I explored Erlang and found it very easy
to pick up. The only challenge for me at the time was thinking the ML way. I
was very excited about the actor model. The syntax never bothered me. In a
way, I actually thought (and still think) it is quite beautiful.

As far as libraries are concerned, google is my repo. I have never understood
the need for gems, CPAN, and so forth, since none of those are any more
regulated for code quality than other random things on the net. Where do
people go to find C or C++ packages? Google for me. But I did browse this for
anything I thought I needed: <http://trapexit.org/Special:UserContributions>

That said, I thought the binaries were a bit painful.

I suppose it just boils down to opinion.

~~~
ericmoritz
I found Erlang hard to understand at first but I was a victim of my own
ignorance. I knew instantly that it's pattern matching feature was incredibly
useful but it wasn't until I read "The Little Schemer"
[http://www.amazon.com/Little-Schemer-Daniel-P-
Friedman/dp/02...](http://www.amazon.com/Little-Schemer-Daniel-P-
Friedman/dp/0262560992) that I was able "get" Erlang.

------
yesbabyyes
The error wrapper is kind of nice, I'll think about adopting it. Basically,
though, I find that CoffeeScript's significant whitespace and lack of cruft in
general yields pretty nice callback code, with indents as a visual indicator
of program flow. Given that you use named functions where appropriate.

The same is true for JavaScript as well, but it's easier to accomplish, IMO,
in CS. TJ Holowaychuk's JavaScript code, for instance, is very readable.

------
Strilanc
Even better than this is the 'await' functionality coming in C#5. The
indentation doesn't increase with each callback, and exceptions are propagated
'across' the callbacks the way you expect.

------
unshift
the fine folks writing the Twisted Python library solved this problem years
ago with the Deferred abstraction and the @inlineCallback decorator. there's a
little bit of a performance penalty but an enormously huge increase in code
readability.

