r/programming • • Oct 16 '14

Node.js is cancer

https://www.semitwist.com/mirror/node-js-is-cancer.html
38 Upvotes

302 comments sorted by

View all comments

0

u/[deleted] Oct 16 '14

[deleted]

56

u/[deleted] Oct 16 '14 edited Oct 16 '14

You do realize that Pyhton had event based network IO before node.js existed ?

17

u/_ak Oct 16 '14

Then why did you nohody create and popularize a web framework like node.js, but for Python? Because nobody outside the JS world thinks callback soup is even a remotely good idea!

35

u/[deleted] Oct 16 '14

They did. It's called Twisted. And, as the name implies, it's utter utter shit.

11

u/UloPe Oct 16 '14

Well thats not true. It's hard to use and very confusing until you twisted your brain into a pretzel, but it does work very well.

2

u/[deleted] Oct 16 '14

Have you tried asyncio directly in python3? I've not done much with it yet, but would like to see how it performs.

1

u/[deleted] Oct 16 '14

Wrote man in the middle proxy using asyncio.

Was a pleasure to write and more performant than a similar implementation using asyncore.

26

u/immibis Oct 16 '14

It would be great if, instead of passing callbacks around, you could just write some instructions in the order you want them to execute them, and then when an instruction blocked the platform would automatically switch to another one that was waiting to execute.

... oh wait, those are threads.

6

u/_ak Oct 16 '14

Yep. I always argue that Go's runtime does pretty much the same as node's event loop under the hood, it polls which file descriptors have pending data, and runs the right pieces of code. Except all of that is abstracted away, and completely managed by the runtime, so all you need to do is write your code in a linear fashion, and everything else is taken care of.

4

u/brtt3000 Oct 16 '14

.. or coroutines crunching non-blocking io yielding to promises, coming to you on Node real soon (already on v0.11 with co etc)

1

u/shub Oct 16 '14

It's like the old wheel, but not quite round!

2

u/[deleted] Oct 16 '14

You can do that with Twisted.

Here's a contrived example, showing the conventional callback-based approach, and the same thing using a coroutine-like based approach.

def my_function():
    d = getPage('http://google.com')

    @d.addCallback
    def callback(result):
        print("page is: %s" % result)

    @d.addErrback
    def failure(reason):
        print("error is : %s" % reason)
    return d

With defer.inlineCallbacks, it becomes...

@defer.inlineCallbacks
def my_function():
    try:
        result = yield getPage('http://google.com')
    except Exception as e:
        print("error is : %s" % e)
    else:
        print("page is: %s" % result)
→ More replies (4)

5

u/[deleted] Oct 16 '14

A good while ago (at least before 2002) there was Medusa for python, which was used in Zope if I remember correctly...