
Contra – Asynchronous flow control with a functional taste to it - bevacqua
https://github.com/bevacqua/contra?1
======
toleavetheman
I think this library looks great. It seems to do just enough, and browser
compatibility with a small filesize is wonderful.

I almost can't believe that all of the other (current) comments are
complaining about the use of the λ character. Unicode is hardly a new concept,
and it is certainly not "hostile" (hyperbole much?).

In fact, as modern languages like Julia become popular, I think we will see
increased use of unicode characters in coding. Julia is very unicode friendly,
which aids scientists and mathematicians when translating formulas to code.
For example, it supports the "element of" operator ('∈') for testing if an
item is in a set. These unicode characters actually _improve_ readability in
many contexts, while being less convenient to type if you're only accustomed
to ASCII.

~~~
xyzzy123
I guess not super hostile, but I just don't know how to type it in emacs or
vim except by memorising the code point :/

e.g. in Vim: Ctrl-V, U, 3bb <ret>

Which is OK for this one library... but if I had delta and epsilon libraries
too I could see it getting to be a pain.

In terms of typing efficiency, 6 keystrokes, it's about the same as just
typing "contra" except harder to remember.

~~~
klibertp
For the quickest workaround if you need only a lambda char, bind something
like this to some keys:

    
    
        (defun my-insert-lambda () 
            (interactive)
            (ucs-insert 955))
    

But there are many different options available in Emacs for inserting exotic
characters, as listed here, for example:
[http://stackoverflow.com/questions/10192341/how-to-enter-
gre...](http://stackoverflow.com/questions/10192341/how-to-enter-greek-
characters-in-emacs) \- I didn't have any need for them, as I only need lambda
character when I'm programming in Racket (which understands this character
natively, which is very nice!), but both abbrevs and input method ways of
doing this look legit.

------
stefanha
Flow control != control flow

[https://en.wikipedia.org/wiki/Flow_control_(data)](https://en.wikipedia.org/wiki/Flow_control_\(data\))
[https://en.wikipedia.org/wiki/Control_flow](https://en.wikipedia.org/wiki/Control_flow)

I expected a "please stop sending until I am ready to receive again"
mechanism.

~~~
bevacqua
There's a queue for that.

------
acjohnson55
This looks pretty cool, but it seems to me it has hardly more than a
sprinkling of "functional taste". Promises are much more functional in the
modern sense of preserving composability _outside_ the abstraction by creating
values that represent asynchronous computations, which can be composed
flexibly with a _then_ method.

------
kennu
Contra? Shouldn't it be Contrl? (Original name is Contrλ)

------
AdrianRossouw
Using extended characters like λ for your library is pretty hostile to users.

~~~
bevacqua
I don't, it's just the name I use on the readme. The library is published as
the `contra` global.

~~~
colinramsay
And in all of the examples on the github page. Why not just get rid of the λ
variable and use `contra` directly? I guarantee this will confuse/frustrate
people otherwise.

~~~
callum85
Yeah it will confuse some but it'll probably pique some people's interest too.
People like memorable little oddities sometimes.

~~~
colinramsay
Sure, but not in their code. All this does is blind people to the genuine
values this project might have.

------
Kiro
> The only reason contra isn't published as λ directly is to make it easier
> for you to type.

I don't understand this. Do you mean "so you don't need to use the λ
character"?

~~~
bevacqua
Yeah

------
jlipps
Nice! Interested in adding the contra approach to
[https://github.com/jlipps/async-showcase](https://github.com/jlipps/async-
showcase)?

------
pabloPXL
I wrote another async replacement for browsers, 4.1k minified.
[https://github.com/aynik/be](https://github.com/aynik/be)

------
kolodny
I wrote library a long time ago to solve pretty much the same problem.

[https://github.com/kolodny/wttt](https://github.com/kolodny/wttt)

------
micahasmith
In order for us to use this in production we ordered all our programmers
keyboards with lambda keys. jk but for real this is a really useful lib

------
iaminsane
Looks like async library but without 90% of code

~~~
aroman
90.88%, actually

[https://github.com/bevacqua/contra?1#comparison-with-
async](https://github.com/bevacqua/contra?1#comparison-with-async)

------
danabramov
Promises are a superior abstraction, easier to reason about, provides
consistent error handling. Sadly (in my opinion), this is an `async`-like
library.

~~~
aroman
What? Why? I disagree on all of those points. Promises are inconsistent[0],
slow[1], and I find them a hassle compared to async. The Node.js core and
community convention is to use callbacks and callback-embracing tooling for a
good reason.

[0] [http://lostechies.com/derickbailey/2013/09/20/consistency-
pr...](http://lostechies.com/derickbailey/2013/09/20/consistency-problems-
with-apis-in-javascript-promise-libraries/)

[1] [http://thanpol.as/javascript/promises-a-performance-hits-
you...](http://thanpol.as/javascript/promises-a-performance-hits-you-should-
be-aware-of/#conclusions)

~~~
notduncansmith
Performance: I cannot honestly remember a single case in my entire Node.js
career where promise execution time was a performance bottleneck.

Inconsistency: If you're consistent in your promise library usage, then
promises will always behave the same way. Wrap libraries as necessary.

Promises are incredibly easy to reason about - the code reads very
synchronously. Until we have native concurrency primitives available at the
language level, I'll settle for ".then". It's pretty much how I'd read it in
my head anyways.

If promises are a hassle, you're probably not using them correctly.

------
WorldWideWayne
I don't get why the special character had to be used.

~~~
aroman
It doesn't. You can use whatever identifier you'd like, just as with every
node module.

~~~
WorldWideWayne
No, I mean within the readme. It only served to confuse things.

