Live data from Hacker News

An Absolute Beginner's Guide to Node.js

blog.modulus.io

51–60 of 71 posts

Re: An Absolute Beginner's Guide to Node.js

#51
post #43

Earlier quoted context omitted.

> 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?

I believe twisted was an inspiration for node.

Re: An Absolute Beginner's Guide to Node.js

#52
post #2

> Basically you're telling it to do something and when it's done it will call your function (callback). This is because Node is single-threaded . Do you mean multi-threaded?

No, Javascript has no notion of threads. Rather than true concurrency and a synchronization mechanism, it has callbacks (upon callbacks upon callbacks).

You can create lightweight threads built on delimited continuations in javascript, same as any language that supports thunks reified as functions.

Re: An Absolute Beginner's Guide to Node.js

#54
post #38

Earlier quoted context omitted.

Node was created to make scripting fast servers easy. Nothing more, nothing less. Because JS (as implemented in the browser and known by many programmers) didn't carry the baggage of blocking IO calls, Ryan thought it would be a good language for an event-loop based server. History of Node.js: http://www.youtube.com/watch?v=SAc0vQCC6UQ

Fast Web servers. There is absolutely nothing there that I could use to make, say, a fast database server.

yes, fast web servers.

Re: An Absolute Beginner's Guide to Node.js

#55
post #50
post #43

Earlier quoted context omitted.

> 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...

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.

Re: An Absolute Beginner's Guide to Node.js

#56
post #50

Earlier quoted context omitted.

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?

Re: An Absolute Beginner's Guide to Node.js

#57
I like this article. I've been learning Node on the side (I'm a Java developer so Node is pretty foreign to me) and really enjoying it, but as it's very different from what I'm used to these kinds of guides are a big help.

Re: An Absolute Beginner's Guide to Node.js

#58
post #43

Earlier quoted context omitted.

> 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).

Re: An Absolute Beginner's Guide to Node.js

#59

Earlier quoted context omitted.

While that's true, I don't believe it's applicable to node.js, so it's a bit out of scope for this article.

People coming from multi-threaded server environments should be aware that multi-threading does in fact exist in Node (scope of parent comment), but it's rather different from other more common concurrent event handling schemes. I.e., you cannot have shared mutable variables across threads (scope of article and ongoing async discussion). For examples, see https://npmjs.org/package/webworker-threads and https://github…

Fascinating. I didn't know that webworkers were available in node.js. I stand corrected, then.

Re: An Absolute Beginner's Guide to Node.js

#60

Earlier quoted context omitted.

> "relative absence of blocking IO calls." Do not confuse "language" with "standard library".

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.

Post reply on HN