News for hackers. Stuff that matters.
Re:We switched to Node.js: the good and the not so good by davidw on Monday January 14, 2013 @07:35AM (#5054375)
> What we liked the most of Javascript was the fact that it’s an asynchronous language ‘by default’.

That's not strictly true - a "while (true)" will lock up a Node process as far as I can tell. I think a more accurate way of stating it would be that "Javascript API's and libraries tend to be written with asynchronous use in mind", with lots of callbacks.

If you want something that's async at a deeper level, Erlang is worth a look.

Re:We switched to Node.js: the good and the not so good by StavrosK on Monday January 14, 2013 @08:53AM (#5054619)
Will a "while True" not lock up an Erlang thread?
Re:We switched to Node.js: the good and the not so good by davidw on Monday January 14, 2013 @08:57AM (#5054634)
No: Erlang has an internal scheduler that makes sure that no process can lock the whole thing up.

It's not impossible to wedge Erlang, of course, it's just not quite so easy.

Re:We switched to Node.js: the good and the not so good by StavrosK on Monday January 14, 2013 @09:02AM (#5054648)
Ah, so it uses preemptive rather than cooperative multitasking. I find that locking the whole thread is usually an error, so preemptive multitasking wouldn't help much there, and I like how cooperative multitasking lets me reason about the program, but I can see the benefits in both approaches.
Re:We switched to Node.js: the good and the not so good by jerf on Monday January 14, 2013 @10:01AM (#5054851)
Erlang does not have a problem reasoning about the program, because it doesn't share any data. They are actually independent from each other in the same ways that two OS processes are independent from each other (that is, there are still resource contention issues but abstract correctness don't unduly depend on each other).

I'm running out of polite ways to say this, but Node advocates really need to learn about other ways of doing things before advocating so confidently that Node's way is better. Cooperative multithreading does not have the reasoning advantage, which is one of the reasons why it has been abandoned for so long at the OS level. It's incredibly harder to work with that preemptive multithreading sorts of things, combined with other techniques that have been developed over the decades.

(Also, I said "Node advocates" and not StavrosK or "you" specifically; I mean that more generally than just your post here.)

Re:We switched to Node.js: the good and the not so good by StavrosK on Monday January 14, 2013 @11:14AM (#5055200)
Oh, I'm speaking from more of a Go/gevent approach. Obviously, a correctly-designed program would try to avoid shared data structures as much as possible, in any language, e.g. for Go you would write goroutines that communicate with channels.

The "reasoning" I was referring to was more that I know that simple things like incrementing a global counter is guaranteed to be atomic. I agree with you that that's still a shared structure, and thus dirty, so I avoid it anyway.

Now that you mention it, I don't actually know why I said that before, since I never write production code like that. I guess I was referring to ad-hoc scripts, where I like knowing that I don't need a lock to guarantee atomic operations, and thus they're a bit easier to write.

Re:We switched to Node.js: the good and the not so good by oinksoft on Monday January 14, 2013 @09:22AM (#5054710)
It will block your process (just like a `receive' does), but a good Erlang/OTP system is generally comprised of a great many processes. If one process can block, your design is wrong, and the system itself is designed to be robust when things block like this. You expect your processes to be blocked, but you design things so that truly concurrent activities are being run in parallel.
Re:We switched to Node.js: the good and the not so good by rdtsc on Monday January 14, 2013 @01:13PM (#5055767)
No.

It is funny you'd ask though, I just read this post yesterday:

How Erlang Does Scheduling :

http://jlouisramblings.blogspot.dk/2013/01/how-erlang-does-s...

Re:We switched to Node.js: the good and the not so good by exo762 on Monday January 14, 2013 @08:57AM (#5054636)
There are no reasons to use busy waiting in Erlang. Ever.
Re:We switched to Node.js: the good and the not so good by davidw on Monday January 14, 2013 @09:07AM (#5054661)
while(true) would be pretty bad form in a Node program too, and doesn't actually seem to be a big problem in practice for people.
Re:We switched to Node.js: the good and the not so good by rdtsc on Monday January 14, 2013 @01:19PM (#5055792)
It is a magnitude easier in Node to block the whole OS process by doing anything CPU intensive. In Erlang, if not using C-bindings, there is nothing a single Erlang process can do to block the whole runtime.
Re:We switched to Node.js: the good and the not so good by StavrosK on Monday January 14, 2013 @09:00AM (#5054641)
There are no reasons to use busy waiting anywhere. This isn't what we're discussing, though.
Re:We switched to Node.js: the good and the not so good by scott_s on Monday January 14, 2013 @10:00AM (#5054848)
Well, yes, there is. When implementing locks, it depends on how likely and how long contention is. If the expected cost of busy waiting is less than the expected cost of interacting with a heavier-weight scheduling system (which may mean crossing the kernel boundary), then busy waiting is better. This is, of course, for lower level codes. For example, spin locks (so-called because they spin - or, busy wait - on a status variable) are frequently used in kernel code, and I have used them in a memory allocator.
Re:We switched to Node.js: the good and the not so good by StavrosK on Monday January 14, 2013 @11:21AM (#5055229)
Sure, in that case, it makes sense. As you say, though, it's for lower-level codes.
Re:We switched to Node.js: the good and the not so good by matthavener on Monday January 14, 2013 @12:06PM (#5055444)
Is it even possible to busy wait in Erlang?
Re:We switched to Node.js: the good and the not so good by rdtsc on Monday January 14, 2013 @01:17PM (#5055787)
Well do you mean per-process or for the whole node? You'd have to go out of your way in any case. For process you could create a tail recursive loop that just calls itself. It will run for 2000 reductions then the scheduler will kick it out and so on. But it own't block other processes.

To block a whole node'd have to perhaps write a native functions a (NIF) and do it there. Which is also a reason to be careful with NIFs, they can kill predictable latency under load, while initially in serial benchmarks they could show a performance improvement.

Re:We switched to Node.js: the good and the not so good by brown9-2 on Monday January 14, 2013 @01:23PM (#5055806)
Beyond this, is there any part of the JavaScript language itself that is inherently asynchronous or enables the writing of asynchronous code?

I believe the answer is no - the async nature is provided by V8 and the core Node libraries.

Re:We switched to Node.js: the good and the not so good by archangel_one on Monday January 14, 2013 @01:50PM (#5055920)
I would say yes, it's very easy to write inline anonymous functions which are very very nice for a primarily callback-driven model. I much prefer Python as a language overall, but I think writing code for "Node.py" would be an awful lot harder.
Re:We switched to Node.js: the good and the not so good by pindi on Monday January 14, 2013 @03:20PM (#5056399)
"Node.py" is Twisted [1] and/or Tornado [2]. And you're definitely correct.

[1] http://twistedmatrix.com/trac/

[2] http://www.tornadoweb.org/

Re:We switched to Node.js: the good and the not so good by xyzzy123 on Monday January 14, 2013 @06:35PM (#5057415)
Agree, Python doesn't feel as natural for callback-style. I do like the gevent (http://www.gevent.org/) or greenlet style code though.
Re:We switched to Node.js: the good and the not so good by mason55 on Monday January 14, 2013 @03:09PM (#5056330)
I disagree. Try writing fully async Java - it's much, much harder without functions as first-class objects and true closures.