Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The whole event loop idea, which is core to javascript, allows for the single-threaded non-blocking I/O in a way that no other popular language does. Because of this, javascript has features that make this type of programming easy - first-class functions, anonymous functions, etc.

So, yes. Non-blocking I/O is a standard library feature, but it works because of language features.



> "The whole event loop idea, which is core to javascript, allows for the single-threaded non-blocking I/O (...)"

Event loops are not a property of JavaScript of any other programming language: Every single GUI Win32 application ever written in C directly calling the WinAPI contains an explicit event loop.

> "(...) in a way that no other popular language does. Because of this, javascript has features that make this type of programming easy - first-class functions, anonymous functions, etc."

JavaScript is hardly the only language, or even the only popular language, to ever have first-class procedures or anonymous procedures. You know what (at some point in time) widely taught language has a procedure data type[1]? Pascal. So why not Node.pas instead?

> "So, yes. Non-blocking I/O is a standard library feature, but it works because of language features."

That countless other languages have. Most of them a lot better designer than JavaScript.

===

[1] Edit: I originally suggested Pascal has anonymous procedures, which it does not.


> allows for the single-threaded non-blocking I/O in a way that no other popular language does.

C# Async and Await - http://msdn.microsoft.com/en-us/library/vstudio/hh191443.asp...


Twisted (Python) and EventMachine (Ruby) don't all of these do the same thing?


Yes. But they are tacked on to the language after the fact rather than built in from the beginning. My experience is that both language and libraries support that kind of pattern better in node than in Python (no Ruby experience with async).


I believe twisted was an inspiration for node.


were those in the language before or after node came out?


async/await are just sugar over the much older asynchronous delegate pattern that has been in the language since day one. So yes, they were.


are they widely used in APIs to e.g. send a query to the sql database or open a file?


Yes.

In .Net 4.5 there are Async versions of the web, file, stream, image and SQL category of functions.

It's also making its way into ASP.Net layer.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: