News for hackers. Stuff that matters.
Re:JavaScript is Eating the World by hood_syntax on Thursday August 24, 2017 @09:16AM (#15089794)
The more time goes by the more I feel crazy for missing whatever would motivate people to use js for anything more than is strictly necessary. Single threaded server??? I mean come on man, I understand you don't need parallelism for a lot of use cases but even if that fits your situation why javascript? It can't be that hard using a different language. I refuse to believe that.
Re:JavaScript is Eating the World by specialist on Thursday August 24, 2017 @11:41AM (#15091006)
My day gig is nodejs. I was interested in the problem space, didn't think too much about the stack. How bad could it be, right? Oops.

The worst aspect of nodejs is code construction (craftsmanship).

Whereas Bill Joy said of Java "Allows you to think both In The Big and In the Small, at the same time." With nodejs, not only is there no Right Way, there's not even a Good Way. You have to mind all the details, plus quite of a few new ones.

Frankly, I'd rather just write 'C' again. If I have to care about the fiddly bits, I'd rather the language not fight back.

My team spends a lot of time mitigating memory leaks and back pressure (bufferbloat due to thread/task starvation). I haven't done this kind of troubleshooting since my 'C' slinging days.

And this is apparently acceptable.

I find the current state of affairs (emperor has no clothes) appalling and baffling.

Re:JavaScript is Eating the World by dboreham on Thursday August 24, 2017 @11:44AM (#15091035)
My take on this (I have had the same experience, fwiw) is that it is like the well-known story of bridges falling down due to experienced engineers retiring (Tay Bridge Disaster, Tacoma Narrows Bridge for example). A new generation of folks who actually believe that "Single Threaded is a benefit" arrive on the scene and make a bridge that falls down..
Re:JavaScript is Eating the World by eropple on Thursday August 24, 2017 @12:32PM (#15091533)
Single-threaded isn't a benefit, but in a world where multi-process isn't a problem, a lot of that is blunted. Granted, for problems that are both compute- and IO-heavy, something like the JVM makes much more sense (so just use it--duh, right?). For throwing bytes over a wire, something like Node is really, really easy and really, really effective. My biggest beef with it is the weak libraries for talking to RDBMSes, that's about it; my API tools of choice remain Ruby/Grape/Grape-Swagger because ROM is so much nicer than anything I've seen in Node, but that's really about it.

Like I said upthread, I used to dunk on JavaScript a lot, but it doesn't make sense nearly as much as it used to, to me.

Re:JavaScript is Eating the World by always_good on Thursday August 24, 2017 @02:25PM (#15092656)

    >Single-threaded isn't a benefit
Huh? Of course it has some benefits. Unfortunately everything is just trade-offs. A benefit of single-threadedness is that you don't deal with the certain pitfalls of multi-threadedness.
Re:JavaScript is Eating the World by defined on Thursday August 24, 2017 @04:09PM (#15093623)
Seriously, use Erlang or Elixir and have both concurrency and ease of programming and debugging relative to Node.js. Spoken as someone who has created multiple Erlang projects with close to zero unintended downtime for months or years in production.
Re:JavaScript is Eating the World by eropple on Thursday August 24, 2017 @06:13PM (#15094512)
I like what I've seen of Elixir. (As a Rubyist by habit, I should.) But it doesn't do what Node does:

Use JavaScript.

We can say 'til we're blue in the face that that doesn't matter (and I do, as a Ruby/Grape guy for APIs), that matters. Lowered impedance mismatch is a thing. I use Ruby because I'm still more productive there--but that's a library problem (RDBMSes), not a language problem.

Node really is good-enough. I'd go for either a JVM or a BEAM-based solution if I was building things where there were significant and meaningful losses on the table if I fucked up, but for most things? Nah. Just...not important enough.

Re:JavaScript is Eating the World by eropple on Thursday August 24, 2017 @02:29PM (#15092684)
If you are dealing with a single-threaded, non-concurrent problem, yes, that's true. Node isn't that. In my experience, the pitfalls of multi-threadedness are more around concurrency than they are parallelism, so that tradeoff strikes me as largely a false one.
Re:JavaScript is Eating the World by always_good on Thursday August 24, 2017 @03:01PM (#15092978)
I'd say the exact opposite. Race-conditions in parallelism are where the classic problems lie.

We aren't going to agree here, but you sounded like you thought your position was axiomatic or something, and that's what I disagree with. Meanwhile I am content that we may have different preferences, that's not a problem.

Re:JavaScript is Eating the World by eropple on Thursday August 24, 2017 @03:10PM (#15093059)
The problem, in every case I can think of (and it intuitively seems true), is continuation, whether it's done in software with coroutines or in hardware with process scheduling/threads. Which is a concurrency problem rather than a parallelism problem, which then expands to "are problems of linearizability concurrency or parallelism?". Which might be a more settled way to answer the question in a CS manner.

Can you describe a race condition that cannot be replicated on a single thread with either preemptive or cooperative multitasking/coroutines? I'm racking my brain and can't come up with one. If your coroutines are deterministically given time, then I guess you can avoid race conditions, but "are my coroutines deterministic" seems like a really difficult thing to conclusively prove in all cases (like, just add network I/O latency), and the conceptual barrier remains the same whether they're deterministic or not.

(Edit: a friend just noted the possibility of writing to memory/disk and reading halfway through, and if you don't have atomic writes that's true, but you can have preemptive, single-process multitasking that interrupts mid-write; that's why we have file system lockfiles, isn't it?)

I use node-async-locks when writing JavaScript sometimes if I have to deal with shared state, because, hey, I might have to await something and come back to this later. (Obviously I try not to, because duh, but sometimes you're stuck with it and can't immutable-all-the-things. So you define a critical section and do your thing.)

Re:JavaScript is Eating the World by eropple on Saturday August 26, 2017 @07:03PM (#15107954)
Coming back to this, I'd really like to direct your attention to my reply. Am I missing something with regards to this?
Re:JavaScript is Eating the World by amorphid on Thursday August 24, 2017 @12:07PM (#15091265)
I used to love to idea of a global interpretator and/or a single thread (coding without concurrency). It was great until it wasn't. Learning Elixir helped me get over that.
Re:JavaScript is Eating the World by dboreham on Thursday August 24, 2017 @01:12PM (#15091956)
The thing is : it isn't an "idea" at all. These projects ended up with a big lock, or not tolerating reentrancy due to history -- they were developed at a time, and in an environment where there were no threads (or where support for threads wasn't of interest to the developer). It's just a bug. Not an idea, not a benefit. All the talk of it being the best way is nonsense invented after the fact to try to justify something that's just broken.
Re:JavaScript is Eating the World by defined on Thursday August 24, 2017 @04:05PM (#15093572)
I'm an Erlang practitioner since 2007 and I approve this message ;)

Learn Elixir or Erlang and show that there's an alternative to Node.js that's both fun and powerful - and battle tested.

Re:JavaScript is Eating the World by specialist on Thursday August 24, 2017 @03:15PM (#15093111)
Ya, my next green field project will definitely use something actor or CSP flavored. Maybe clojure based, more likely Elixir or equiv.
Re:JavaScript is Eating the World by eropple on Thursday August 24, 2017 @12:30PM (#15091510)
> Frankly, I'd rather just write 'C' again. If I have to care about the fiddly bits, I'd rather the language not fight back.

Instead, you'd rather the language be written with conscious land mines in it?

Like, I have a history of dunking on JavaScript. (Though, to be fair: ES6+ is better! It's a lot better. I kinda like it.) But C is unsafe as hell. The list of people who should be writing C is super short.

If you're running into memory links in Node, that points to bad native code or handles that are never getting removed. That's not something easier in C, unless you also like buying yourself double frees that you have to worry about. And backpressure is an architectural problem--it doesn't go away in another language, the ephemera of it just makes the problem surface in a different way.

Maybe what you're writing isn't appropriate for Node. Much of what I write isn't--if I start seeing buffers, I start reaching for another ecosystem, usually the JVM. But that's a far cry from a meaningful criticism of Node for what it's good at. Use what's good where it makes sense. Use other things where they make sense. Revisionism to have C make sense, in 2017, when we have modern, clean C++ and Rust both and Go if you really don't actually care about type systems, makes me really skeptical.

Re:JavaScript is Eating the World by specialist on Thursday August 24, 2017 @03:11PM (#15093069)
What are the ideal use cases for nodejs?

We have a handful of stupid simple http servers. We use express, redis, aws-sdk, pino, misc. Responses are mostly JSON.

The http-request module has given us the most fits. I question that any one has ever used it for more than toy problems.

The redis module is also an engineering marvel. I gave up trying to add a rate throttling shim. The goal is to limit the number of concurrent requests. Because when our app is under load, we're not processing redis responses fast enough, so redis server's outbound client buffers grow and will eventually OOM ABEND the server. So I wrote our own stupid simple redis thing using async.queue as a poor mans thread (task) pool. Trivial. Eg my REPL parser is 1/3rd the size of node-redis-parser. Works great. I keep thinking I must be missing something.

From my reading, hapi (successor to express) does an inbound backpressure thing. I'll be trying that out asap.

Much as I hate Spring, AOP, jedis, annotations, jaxrs, log4j... I've never had these kinds of nuts & bolts problems. Now I kinda miss the elephant gun approach.

PS- I can only assume the on drain event strategy was someone's idea of a practical joke. Maybe its a uvlib thing.

Re:JavaScript is Eating the World by peterashford on Thursday August 24, 2017 @06:48PM (#15094742)
"I find the current state of affairs (emperor has no clothes) appalling and baffling."

JS is the only language on the browser after Java and Flash were killed off.

Brendan Eich created JS.

Brendan Eich runs Mozilla.

No new browser language occurs unless the big players (including Mozilla support it)

Mozilla have killed all attempts to add new languages to the browser.

Q.E.D. - language monoculture due to one creator forcing his creation on everyone and denying anyone the chance of doing things differently.

At least Web Assembly offers some hope for a sane future where we can actually choose the right tool for the job rather than the only tool for the job.

Re:JavaScript is Eating the World by dragonwriter on Thursday August 24, 2017 @06:50PM (#15094753)
> Brendan Eich runs Mozilla.

Ran. Very briefly.

Re:JavaScript is Eating the World by alayek on Thursday August 24, 2017 @09:30AM (#15089908)
Node is single threaded, in the sense that your code runs in a single thread. Your code assigns microtasks, to be executed later.

Basically, if you write in Node JS, there's no concept of a thread. The thread API is not visible or accessible to the developer.

This forces you to think from the ground up about asynchronous operations that would take some time to complete - file opening, network requests etc., and have you group all tasks dependent on that time-consuming task, separately.

In Node, you are not supposed to block the event-loop that runs in that single thread and queues the tasks.

Node JS has shown over the years that it scales well (maybe not as good as Go or Elixir, but enough for most use-cases).

Node also offers lot of great tools, that can be easily added to your project via NPM / Yarn. The Node ecosystem has a solution for virtually any task you might need to do repeatedly in a project.

Just to be clear, I am not saying Node or its ecosystem is perfect. There's always room for improvement.

What I am saying is that what appears as an obvious flaw, is not really a flaw. The language allows other approaches to solve the problem.

Re:JavaScript is Eating the World by falcolas on Thursday August 24, 2017 @09:43AM (#15090026)
Using non-blocking IO is a very old trick. Even nginx does exactly this, and it's written in C. The ability to use non-blocking IO does not make a language unique in any real fashion.
Re:JavaScript is Eating the World by alayek on Thursday August 24, 2017 @10:02AM (#15090169)
I have never claimed that it's unique. In fact, most ideas in tech is just old wine in a new bottle.

However, I guess what made it appealing initially, was that it uses a syntax known to a lot of web developers. The callback pattern helped.

Although these days, we have been moving away to generators or async-await.

Re:JavaScript is Eating the World by falcolas on Thursday August 24, 2017 @10:18AM (#15090278)
> a syntax known to a lot of web developers

This is the key. And it reflects poorly on them for that. Syntax is the easiest part of a language to learn. The nuances of behavior is the hard part - and those nuances change as you move from the browser to the server; what makes good browser code will not make good server code.

In reality they shunned a ton of knowledge and community support to keep a particular (and particularly mediocre) syntax. Even today, years after Node has reached popularity and many lessons have been learned, developers with no experience outside the browser think they can write perfectly good server code, simply because they know the syntax. Never mind that all of the design patterns change. Never mind that the core libraries they use change. Never mind that they suddenly have to be cognizant of how much CPU time their code takes.

Re:JavaScript is Eating the World by flavio81 on Thursday August 24, 2017 @11:38AM (#15090975)
> Even today, years after Node has reached popularity and many lessons have been learned, developers with no experience outside the browser think they can write perfectly good server code, simply because they know the syntax (...)

This is really true and it's sad, because it leads to more security problems on everyday software.

Re:JavaScript is Eating the World by tim333 on Thursday August 24, 2017 @11:43AM (#15091027)
Beyond the syntax, an event loop is conceptually simple in a way that other models often are not. (For example https://news.ycombinator.com/item?id=11555866 had a how to Python async and I found it a bit confusing compared to js).
Re:JavaScript is Eating the World by jdc0589 on Thursday August 24, 2017 @10:51AM (#15090542)
It has nothing to do with the language, there were other serverside javascript frameworks before node; they didn't take off (e.g. Narwhal).

Node's success has everything to do with the environment itself in combination with the language. The node runtime, the associated stdlib, and most open source/3rd party modules have been written for a non-blocking runtime from day #1. The same stuff can be achieved in plenty of other languages/stacks (e.g. Python + Twisted), but you have much more work to do validating that every single library you use plays nice with async io, sometimes you have more event loop housekeeping responsibilities, etc...

Re:JavaScript is Eating the World by gaius on Thursday August 24, 2017 @10:55AM (#15090583)
Node's success has everything to do with the environment itself in combination with the language.

Let's be honest: it is nothing to do with either of those and purely a matter of fashion. In a couple of years at most there will be a new new thing and everything will revert to version 0.1, keeping everyone busy but making no actual progress. Gotta soak up those CPU cycles the hardware people are giving us somehow right? Can't let the users get any of that speed for themselves!

Re:JavaScript is Eating the World by vim_user on Thursday August 24, 2017 @12:01PM (#15091208)
After two decades in this industry, I've come to the same conclusion. Developers may use logic in coding, but trend-wise, we're bunch of herds following whatever others are doing. We forget whatever lessons we learned previously whenever something new comes out. It's good to see there are others who see insanity in it as well.
Re:JavaScript is Eating the World by kolanos on Thursday August 24, 2017 @12:54PM (#15091774)
There is a logic to following trends, but it has nothing to do with the problems being solved and everything to do with remaining relevant in the workforce.
Re:JavaScript is Eating the World by fundabulousrIII on Thursday August 24, 2017 @12:34PM (#15091551)
I agree with this. I've seen the same but the core problem is we don't learn from others mistakes: we prefer to rely on our own tool-making skills to demonstrate increased facility while making similar mistakes.

The thing missing in developers that I have decried over and over in this devop/agile movement is that SAs had discipline and an ordered idea and that developers exist to perturb the norm to better effect. The two ideas are not readily reconcilable.

Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @11:29AM (#15090886)
>Let's be honest: it is nothing to do with either of those and purely a matter of fashion.

Let's be honest: if you need "fashion" or "idiocy" etc to explain a trend in tech, you don't have an explanation.

Your explanation wouldn't even explain why it was Node+JS that got to be "in fashion" and not something else from the 20000 options.

Re:JavaScript is Eating the World by gaius on Thursday August 24, 2017 @11:32AM (#15090909)
Your explanation wouldn't even explain why it was Node+JS that got to be "in fashion" and not something else from the 20000 options

That's the point. There is no explanation, other than the same reason that bellbottoms are in again this year. Or out, I don't actually know.

We pretend like we're "engineers" or "scientists" but there's nothing objective about what we do...

Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @11:37AM (#15090964)
>That's the point. There is no explanation, other than the same reason that bellbottoms are in again this year. Or out, I don't actually know.

You mean you can't come up with one. Because for me, which followed the scene for 20+ years, there is a perfect explanation.

Re:JavaScript is Eating the World by gaius on Thursday August 24, 2017 @12:02PM (#15091212)
which followed the scene for 20+ years

I had a homepage in 1994. I've seen them all come and go. This one's no different.

Re:JavaScript is Eating the World by abritinthebay on Thursday August 24, 2017 @12:08PM (#15091275)
Mhmmm 1994 here also. Your take is shallow, pointless, and meaningless.

It’s as relevant as saying we don’t write apps in COBOL or Modula2 anymore.

Re:JavaScript is Eating the World by RugnirViking on Thursday August 24, 2017 @12:15PM (#15091353)
I have no horse in this race; Care to share the perfect explanation?
Re:JavaScript is Eating the World by jessaustin on Thursday August 24, 2017 @01:20PM (#15092045)
Re:JavaScript is Eating the World by abritinthebay on Thursday August 24, 2017 @12:06PM (#15091252)
Your personal lack of imagination and insight doesn’t mean there isn’t a reason (there are several, some extremely obvious).
Re:JavaScript is Eating the World by dasil003 on Thursday August 24, 2017 @11:58AM (#15091177)
You have it all backwards. Fashion is the reason you hate it, but before it was fashionable it was not. I get that you're bitter and angry, but you do yourself no service by sticking your head in the sand and willfully ignoring the forces that drive popularity.

I'm frustrated that better stuff doesn't win in the market as well, but I've been a web developer 20 years and Node's appeal was pretty obvious and exactly as the GP states. Without that it would not have gained traction to become fashionable.

Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @02:25PM (#15092653)
And nobody really wanted to do these message passing single threaded event loops in other languages, because they could just learn how to use threads instead.

The real innovation that the Node environment and the Javascript language offered is one of marketing to developers who did not know better. Because there were no I/O paradigms in Javascript, one could be created to support this way of doing things, and there was no competing paradigm that people could point to in Javascript to say "Why would I do this when I could just use threads? It's not that hard."

With that out of the way, the floodgates opened, because once the first few people started adopting it because they did not understand threads, it was only a matter of time when "front end" people adopted it, because they did not know any languages other than Javascript. And thus, the current fad was born.

Re:JavaScript is Eating the World by yxhuvud on Thursday August 24, 2017 @01:40PM (#15092249)
Even nginx? Nginx is fairly new compared to all the really old C code.
Re:JavaScript is Eating the World by jcelerier on Thursday August 24, 2017 @09:34AM (#15089938)
> In Node, you are not supposed to block the event-loop that runs in that single thread and queues the tasks.

well, sure, but ten years ago it was already a given that one would just spawn one event loop per thread and have them communicate with messages, so why is it so hard for node ?

Re:JavaScript is Eating the World by jononor on Thursday August 24, 2017 @10:07AM (#15090201)
I/O is not going to be any faster by having more threads. More threads are not gonna give you more RAM either. And CPU-bound tasks are only faster if the OS you are running in exposes multiple CPUs. With VMs and containers with focus on horizontal scaling (many relatively small machines) that is not the case either. Effectively the message-passing communication between threads still exists, but has moved outside the service: done by a load-balancing HTTP router and/or a message broker like RabbitMQ. Another example is when using out-of-process persistence like with Redis.
Re:JavaScript is Eating the World by vardump on Thursday August 24, 2017 @06:09PM (#15094486)
> I/O is not going to be any faster by having more threads.

That's not true on NUMA systems with multiple CPU sockets. You should have at least one thread per NUMA region for optimal results. Critical for example for running multiple 40 or 100 Gbit ethernet adapters.

Then again, you probably aren't going to run Node.js on those systems, at least not for handling heavy I/O.

Re:JavaScript is Eating the World by jononor on Thursday August 24, 2017 @06:30PM (#15094620)
As far as I can tell, Node.JS actually does use multiple threads for I/O, both for for networking and filesystem operations. But this implementation detail is not something programmers using it needs to think about.
Re:JavaScript is Eating the World by jcelerier on Thursday August 24, 2017 @06:48PM (#15094743)
> I/O is not going to be any faster by having more threads.

the world doesn't revolve around making HTTP servers. Maybe you aren't writing apps that do parallelizable serial computations but please don't generalize.

Re:JavaScript is Eating the World by fundabulousrIII on Thursday August 24, 2017 @11:01AM (#15090635)
Your paradigm is showing.
Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @11:30AM (#15090893)
Notice how this doesn't even mean anything.
Re:JavaScript is Eating the World by fundabulousrIII on Thursday August 24, 2017 @11:44AM (#15091041)
Sure it does. Ask a direct question get a direct answer.

Backend and file systems, network and systems middleware do not need the abstraction model and overhead of a language designed to add dynamic content to fucking WEBPAGES because it can and it seems easy.

Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @03:17PM (#15093135)
>Backend and file systems, network and systems middleware do not need the abstraction model and overhead of a language designed to add dynamic content to fucking WEBPAGES because it can and it seems easy.

Well, file systems nobody writes in JS, so that's irrelevant.

As for "network and systems middleware" depending on what it does it can be a great fit for JS and especially Node, which is a lightweight logic layer on top of libuv.

Re:JavaScript is Eating the World by fundabulousrIII on Friday August 25, 2017 @11:36AM (#15099201)
Too literal. It's the file system syscalls translated into node which are the problem. Anytime you have the potential to block you lose the relatively clean event loop and enter libuv which is a thread provider.

'Lightweight logic layer on top of libuv': well if I can design, predicate and tout my language on 'event' orientation but then when it needs to do something else it becomes a thin logic layer over the hosts threading model: that's just a win!

Re:JavaScript is Eating the World by atoko on Thursday August 24, 2017 @02:10PM (#15092524)
Why not? Performance critical parts can be compiled down, which i'm sure most data store libraries already are
Re:JavaScript is Eating the World by fundabulousrIII on Friday August 25, 2017 @12:38PM (#15099839)
My sides.
Re:JavaScript is Eating the World by dboreham on Thursday August 24, 2017 @11:54AM (#15091142)
Because Node is just a very thin wrapper around V8 and V8 has a limitation that it isn't re-entrant (can't handle multiple threads without breaking).
Re:JavaScript is Eating the World by creatonez on Friday August 25, 2017 @03:52PM (#15101641)
>well, sure, but ten years ago it was already a given that one would just spawn one event loop per thread and have them communicate with messages, so why is it so hard for node ?

This is exactly how backend Node.js development is done. The tradeoff is that processes are used instead of threads, which uses more memory but is magnitudes easier to work with than traditional threads where mutable bits of memory are shared.

Sure, Rust solves these problems but Node still has a place in the world: it is established, easy to pick up, and can share code with the browser. A decent solution to modern web development complexity.

Re:JavaScript is Eating the World by pan69 on Thursday August 24, 2017 @04:55PM (#15093978)
Personally I have no real objections to JavaScript as a language but somehow I get the feeling that, in many situations, NodeJS is more a problem than a solution. I.e. JavaScript and NodeJS are two different things and I think they shouldn't be treated as the same thing (i.e. NodeJS is JavaScript and vica versa). NodeJS could have been shipped with a different language (Lua?) but I guess NodeJS surfaced around the same time Google released their V8 engine, so...

To me it seems that NodeJS solves a very specific problem; handling many simultaneous persistent network connections (i.e. websockets). I can't help thinking of NodeJS as fundamentally being a programmable socket server. I.e. its purpose is to solve a network problem, not a business logic problem.

The problem for me, when I work on large(r) apps that run in NodeJS, is that there is a certain "mental overhead" associated with it. NodeJS has this non-blocking IO, event driven architecture for a very specific reason which makes total sense when you solve IO problems (such as handling many simultaneous network connections) but this behaviour somehow seems to trickle down into business logic. With NodeJS I find myself writing non-blocking, event driven business logic because the environment in which my code runs dictates this. Somehow that doesn't make sense to me. To me business logic is inherently synchronous.

Now there are some really clever ways to compensate for this such as the Promise and with never versions of JavaScript there are even new language features to help battle what was originally known as the "callback soup". However, no matter how clever and admirable each of these features are, to me they seem to compensate for a fundamental problem in the run-time environment (NodeJS) that actually makes it not really suitable for anything CRUD and beyond.

Re:JavaScript is Eating the World by ralusek on Thursday August 24, 2017 @01:23PM (#15092076)
For the millionth time: It is not accurate to refer to it as single threaded.

The language is non-blocking, so any asynchronous tasks (DB read/writes, disc I/O, cache, http, etc) will immediately jump to processing the next request the moment it is not doing blocking computation.

Non-blocking:

    [aa][bb][cc][/aa][/cc][/bb][dd][ee][ff][gg][/dd][/ff][/gg][/ee]
Blocking-threaded:

    [aa]------------------------[/aa][ff]----------------------[/ff]

    [bb]------------------------[/bb][gg]----------------------[/gg]
    
    [cc]------------------------[/cc][ee]----------------------[/ee]
    
    [dd]------------------------[/dd]
Depending on how many threads you can get going at once, you may be able to achieve comparable performance doing threading, but nonblocking is basically leaving 0 time on the core wasted and limited to the speed of the event loop.

And then on top of that, clustering module is used to do the same thing on every core.

Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @02:35PM (#15092745)
It is accurate to refer to it as single threaded, because it executes with a single thread. "Non-blocking" is an orthogonal concept to the number of threads being used.

You can have "non-blocking" and multiple threads at the same time.

Re:JavaScript is Eating the World by pier25 on Thursday August 24, 2017 @03:22PM (#15093174)
Isn't it actually 2 threads at the minimum?

The V8/JS thread and the C++ thread?

Doesn't the C++ part create threads in some cases when needed?

Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @06:22PM (#15094572)
I doubt that is accurate, but if it is, it is irrelevant; those "C++ threads" are not available to you to use in your program the way you see fit.
Re:JavaScript is Eating the World by lunchables on Thursday August 24, 2017 @09:25AM (#15089865)
I just tell myself it's because the sales pitch is so appealing: learn, and use, one programming language on the front end and back end of your web site.

I've never written anything on node.js, but that's the only argument that's ever given me pause.

Re:JavaScript is Eating the World by falcolas on Thursday August 24, 2017 @09:46AM (#15090048)
It honestly doesn't give me pause, since the impedance mismatch between JavaScript and backend programming is so great.

To me, the fact that Node has to add a library with custom semantics just to allow a basic 'open' on a file handle is a huge warning flag to me.

Re:JavaScript is Eating the World by ridiculous_fish on Thursday August 24, 2017 @12:14PM (#15091346)
Favorite node / libc impedance mismatch is the stat() call. stat() returns an inode, which is a 64 bit integer. But JS doesn't have 64 bit integers, so it just gets rounded to the closest representable double. So node will sometimes identify two different files as the same file.

https://github.com/nodejs/node/issues/12115

Re:JavaScript is Eating the World by devnill on Thursday August 24, 2017 @11:34AM (#15090925)
>To me, the fact that Node has to add a library with custom semantics just to allow a basic 'open' on a file handle is a huge warning flag to me

What do you mean? The fs module shipped with node is pretty much just a wrapper for libc. Hell, it even links to the open(2) manpage in the docs for usage information.

Re:JavaScript is Eating the World by todd3834 on Thursday August 24, 2017 @10:50AM (#15090537)
What does it warn you about? Not trolling, honest question.
Re:JavaScript is Eating the World by falcolas on Thursday August 24, 2017 @11:02AM (#15090640)
That JavaScript was not designed to work as a *nix (or Windows for that matter) server language. And that any attempts to make it work as a server language are going to include some major workarounds to fit that round peg into a square hole.

You can still make it work; but you can script a web page's interactions in C as well. That doesn't make it the right thing to do.

Re:JavaScript is Eating the World by ovao on Thursday August 24, 2017 @11:40AM (#15091000)
I'm not a particular fan of JavaScript on the server these days, but when you have a large number of developers who know JavaScript from the front-end world and a language ecosystem that's quite large and relatively robust, I would argue that doing those "major workarounds" (which aren't so major, really) to make server-side JavaScript an accessible option at least very closely resembles the "right thing to do".

Should we collectively eschew what's possible due to individual language gripes?

Re:JavaScript is Eating the World by falcolas on Thursday August 24, 2017 @02:57PM (#15092944)
Here's my thoughts about that from a sibling thread:

https://news.ycombinator.com/item?id=15090278

TL;DR: Writing JavaScript for the browser won't really help you write good JavaScript for the server.

Re:JavaScript is Eating the World by ovao on Thursday August 24, 2017 @03:46PM (#15093382)
While I think we agree on points, I also feel like your argument is kind of an overgeneralization. There are knowledge points specific to Node, but developing good code for the browser has similar land mines (referring mainly to asynchrony here) as developing for the server. The problems that exist at the language level, and best practices, are generally applicable to both the server and the browser.

As far as libraries are concerned, it was never my experience that the landscape changed drastically from one to the other. Most of the libraries I look at/use for the front-end today advertise themselves as both for Node and for the browser.

Re:JavaScript is Eating the World by fundabulousrIII on Thursday August 24, 2017 @12:46PM (#15091689)
No. We should collectively evaluate competency and correctness of a developer and language for it's best purpose as in any adequately run job interview.
Re:JavaScript is Eating the World by ovao on Thursday August 24, 2017 @01:33PM (#15092161)
> collectively evaluate competency and correctness of a developer

I'm sorry, is this a dig at Ryan Dahl, or of JavaScript/Node developers in general? I'm having trouble understanding what point you're addressing with this comment.

As for evaluating languages for their "best purpose", I think that's a very complex discussion that doesn't necessarily yield a best (or cost effective/productive) result. And certainly, as we've seen routinely evidenced, using a different language on the server is no panacea.

Re:JavaScript is Eating the World by fundabulousrIII on Thursday August 24, 2017 @01:41PM (#15092259)
I'm sorry, what don't you understand? Complexity is best discussed by those who introduce it.

To be clear: I said js is misplaced on the 'server' side and is a wart in general when applied in that context. Any educated comment on these sentiments?

Re:JavaScript is Eating the World by ovao on Thursday August 24, 2017 @02:32PM (#15092709)
> what don't you understand

Exactly what I asked.

> Any educated comment on these sentiments?

Without clarity on the sentiments themselves there's not a lot to elaborate on without simply fumbling in the dark. If the concern, though, is that, in Node, you live and die by an asynchronous event loop, I'd say that's not a small footgun. I don't think that's in dispute. I'd also say that the presence of footguns doesn't, by itself, disqualify a language from being used in any particular context.

As for JavaScript being a wart, I don't really agree with that sentiment. I think that's attributable to some pretty strong and level-headed language evolution making what was once a very blunt scripting instrument into something somewhat reasonably suited to larger-scale applications.

Re:JavaScript is Eating the World by defined on Thursday August 24, 2017 @04:39PM (#15093853)
JavaScript is objectively, demonstrably a badly-designed, error-generating language for which countless libraries, generators, and higher-level languages and frameworks such as Elm and TypeScript have been created to compensate for its shortcomings - and it most especially does not belong on the server side.

It is the poster child for the "If the only tool you have is a hammer..." maxim.

Its appeal derives almost completely from its presence in probably every major browser, where it was placed for DOM manipulation and was stressed way past its design envelope over time, leading to the increasingly dystopian web development landscape we progressively inhabit.

If it is ultimately victorious, it will be in spite of its design, not because of it. Those of us who are old enough to remember will cringe at the pain we endured over the years because of the widely used Intel 808x architecture as it evolved (small/medium/large/huge memory models, and segment registers, anyone?), not because it had the greatest merit, but because of its market penetration.

History repeats itself.

Re:JavaScript is Eating the World by ovao on Thursday August 24, 2017 @06:57PM (#15094790)
I really don't disagree on any particular point. I only take issue with the suggestion that it simply shouldn't be an option. In the past I probably would've said the same about PHP, which sits pretty squarely in the same camp as JavaScript for its "victory despite design".

All things considered, a craftsman simply uses a tool to do a job. Often it doesn't involve much fanfare. I wouldn't say that modern JavaScript is quite as blunt an instrument as a hammer, but hey, if you're good with a hammer...

Re:JavaScript is Eating the World by woah on Thursday August 24, 2017 @11:26AM (#15090854)
Js is a scripting language that relies on the program being scripted to interact with the outside world. In browsers, this is the DOM and xhr APIs. On servers, this is the node stdlib which lets you interact with the system. The fact that this kind of modularity bothers you is bizarre.
Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @02:38PM (#15092767)
It is a modularity that is an unnecessary point of failure compared to other choices available, and involves poor abstractions for Javascript to use things it was not intended to use.
Re:JavaScript is Eating the World by collyw on Thursday August 24, 2017 @03:41PM (#15093338)
Its been a while since I wrote and Java, but when I did you needed a page of code just to open a file.
Re:JavaScript is Eating the World by Larrikin on Thursday August 24, 2017 @05:53PM (#15094379)
Kotlin is slowly becoming s language that can do all of that. It's production ready for anything that uses java, js support is coming along great, and their slowly moving towards native.
Re:JavaScript is Eating the World by ashark on Thursday August 24, 2017 @10:54AM (#15090566)
The front end/back end sharing argument never appealed to me. In practice, how much are you actually going to be able to share? No way it's worth it.

What's finally got me writing way more Javascript than I'd like to is React Native. It's by far the easiest way I know of to share code between iOS and Android, it papers over a lot of Android's irritating/broken UI bits (introducing others, but overall improving the situation), and you actually can share much of your code (practically everything but the UI layer) with a web client—and even... spits... Electron. RN's performance isn't even terrible, especially compared to cross-platform mobile frameworks that have come before it (and to Electron spits)

Hopefully Webassembly will save us in another couple years, and we'll be able to do the same thing in any of several much better languages.

[EDIT] though definitely keep your sanity and use Typescript. I'd have probably jumped off a bridge by now if I were having to do all this in actual JS, of any flavor.

Re:JavaScript is Eating the World by jtmarmon on Thursday August 24, 2017 @11:13AM (#15090747)
the front/backend sharing stuff matters more these days with server side rendered apps, but I've used nodejs plenty for this lifetime and have no plans to touch the stuff again for serious applications
Re:JavaScript is Eating the World by duderific on Thursday August 24, 2017 @01:31PM (#15092150)
It's kind of funny how you say "these days with server side rendered apps". At one time not so long ago, there were only server side rendered apps.
Re:JavaScript is Eating the World by Someone on Thursday August 24, 2017 @02:09PM (#15092522)
I think most of what you share is the effort needed to learn the language.

Also, it 'helps' if both server and client are single-threaded, because then, you can use similar solutions on both server and client (even if they sometimes aren't the most pleasant approach for solving your domain)

I hope that Web Assembly will take of and get a decent interface to the DOM, allowing developers to pick other languages in the role that JavaScript now has.

Re:JavaScript is Eating the World by alayek on Thursday August 24, 2017 @09:44AM (#15090030)
You should try. I come from a traditional Java shop, and a year ago wouldn't have thought of doing anything serious with Node JS.

Today, I do front-end React stuff as well as back-end servers with Node JS. I have been happy with it so far.

With some type-system like Flow or TypeScript, you can manage huge projects in Node JS.

I happen to like the community, CLI tools written in Node, and the plethora of open source libraries built on top of Node.

This also has a downside. Your libraries can get outdated quite fast, you would have to keep up with new language syntaxes etc., and remember which syntax is supported by which version of Node etc.

But so far, I think Node is headed in the right direction.

Re:JavaScript is Eating the World by mschuetz on Thursday August 24, 2017 @09:43AM (#15090020)
With ES6, JS became a really nice scripting language. Personally, I'm glad to see more and more projects that use javascript outside of web browsers and I've also added V8 to my most recent C++ project. The only major drawback in my opinion is, that it's not statically typed.
Re:JavaScript is Eating the World by flavio81 on Thursday August 24, 2017 @10:53AM (#15090561)
The deeper problem is that JS is not strongly typed. Typescript gives you static type checks but the runtime is still weakly typed and will still do all sorts of weird type conversions.
Re:JavaScript is Eating the World by monsieurbanana on Thursday August 24, 2017 @11:19AM (#15090801)
Theoretically, to what extend could the weird type conversions be prevented with the use of a strict linter? My intuition would be all, but I haven't thought much about it.
Re:JavaScript is Eating the World by flavio81 on Thursday August 24, 2017 @11:40AM (#15090992)
Once code reaches a certain complexity level (and mind you, the threshold is rather low), you'll need dynamic generation of code and data (or else, write 10x the amount of lines of code). For this to happen in a safe way, you really, really, do need the runtime to be strictly typed.
Re:JavaScript is Eating the World by 0xffff2 on Thursday August 24, 2017 @01:12PM (#15091957)
Are you making this claim about JavaScript or as a general statement? I've probably written less than 1000 lines of JS ever (and that only for hobby projects), but I would strongly disagree with this statement as applied to C++, Java, etc.
Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @02:45PM (#15092830)
I'm sorry, I'm confused by the way you expressed that. The argument was you need strict typing for large projects. C++ and Java have strict typing. What exactly is the basis of your strong disagreement?
Re:JavaScript is Eating the World by flavio81 on Thursday August 24, 2017 @08:14PM (#15095142)
My comment is applied to any language with weak typing. Example: Javascript, PHP, and (sadly) C, particularly when using pointers to void. However, in C it's okay since there are big performance gains when you have full control of the memory.
Re:JavaScript is Eating the World by mschuetz on Thursday August 24, 2017 @12:14PM (#15091344)
Strong typing is a start but not enough for my taste. Static typing serves as documentation and compile time bug check, which is awesome to have. I'd like to have both, without the detour over typescript.
Re:JavaScript is Eating the World by seanwilson on Thursday August 24, 2017 @12:50PM (#15091732)
I don't think you're going to get strong types in standard JavaScript any time soon. Isn't TypeScript a very good compromise right now?
Re:JavaScript is Eating the World by flavio81 on Thursday August 24, 2017 @08:15PM (#15095148)
My take is that having dynamic typing plus strong typing is a (pretty) good compromise. And static typing plus weak typing, insufficient.
Re:JavaScript is Eating the World by seanwilson on Thursday August 24, 2017 @08:50PM (#15095309)
What languages would you put in these two categories?
Re:JavaScript is Eating the World by flavio81 on Friday August 25, 2017 @12:06AM (#15096042)
Not all languages but here's a list:

dynamic typing, strong typing: python (for the most part), Scheme

dynamic typing, weak typing: Javascript, PHP

static typing, strong typing: Pascal, Ada, Java, C#

static typing, weak typing: C, Typescript, perhaps others

SPECIAL CASES:

strongly typed, dynamically typed, but with some compilers it can also be statically typed: Common Lisp

strongly typed, statically typed but can infer types: Haskell, ML family

strongly typed, can infer type with "auto" keyword: C++ (latest version)

non-typed: Machine language, assembler, perhaps Forth

Re:JavaScript is Eating the World by seanwilson on Friday August 25, 2017 @01:02AM (#15096236)
What better alternative do you have to TypeScript right now though that you can use practically with existing libraries? Perfect is the enemy of good. TypeScript can capture more complex properties than C as well.
Re:JavaScript is Eating the World by gmac on Thursday August 24, 2017 @09:47AM (#15090056)
I agree. On the whole, I think JS is a middlingly-nice language. It has some good bits and some bad bits. ES6 brings a whole lot more good bits.

I sometimes think we could do with a bit more thanking-our-lucky-stars that the language that got entrenched on the web wasn't, say, VBScript (which IE did use to support).

For your major drawback, there's TypeScript.

Re:JavaScript is Eating the World by nerdwaller on Thursday August 24, 2017 @09:50AM (#15090078)
The real issue with js (node) as a "scripting language" is the lack of a stdlib. A nice thing about writing a Python script is you know the stdlib is there on your remote machine (since some version of Python is on most systems by default other than windows).
Re:JavaScript is Eating the World by randiantech on Thursday August 24, 2017 @09:46AM (#15090043)
Indeed, although Typescript is a good solution to have more OOP based abstractions, like Generics, Abstract Classes and Interfaces.
Re:JavaScript is Eating the World by Arzh on Thursday August 24, 2017 @01:24PM (#15092090)
The argument that people always throw at me is that too hard for people to know two languages, well, for frontend devs to know two languages. Now in a perfect world the frontend people who just can't figure out two or more languages would never touch the backend but the world of software now is "that'll do" not "what is the right tool." It's a shame to me really but I'm not a frontend dev for a reason.
Re:JavaScript is Eating the World by defined on Thursday August 24, 2017 @04:21PM (#15093718)
> The argument that people always throw at me is that too hard for people to know two languages, well, for frontend devs to know two languages.

This is ridiculous from the point of view any professional developer. I know that this is your point, and I'm just amplifying it. I (and many other professionals I work with) know - and use on a daily basis - so many more than 1 language that it's sincerely baffling to grok a world that promotes "One language fits all". That's without even considering the parlous state of npm and its libraries.

Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @02:32PM (#15092708)
If "frontend devs" are really, truly, genuinely capable of only holding one language in their heads, and that language is Javascript, then we should deprecate the term "frontend developer" and replace it.

I would propose "person who can only be at most half-competent," except that is too wordy and probably too charitable.

Re:JavaScript is Eating the World by tempodox on Thursday August 24, 2017 @02:17PM (#15092587)
The argument that I'd throw back is that you're not a programmer if you only know one language or only one execution model.
Re:JavaScript is Eating the World by tchaffee on Thursday August 24, 2017 @10:53AM (#15090559)
> whatever would motivate people to use js for anything more than is strictly necessary.

If that's the primary language you are good at, from coding frontend apps, then it's pretty nice to be able to switch to writing backend code without having to do a language context switch. Muscle memory along with your memory about library methods all just continue to flow.

> It can't be that hard using a different language.

If I'm better at one language than another, it is at least somewhat harder. Why struggle when you can flow?

Re:JavaScript is Eating the World by rootlocus on Thursday August 24, 2017 @11:16AM (#15090770)
> If I'm better at one language than another, it is at least somewhat harder. Why struggle when you can flow?

If you're better with screwdrivers, why struggle with a hammer?

JavaScript has a painfully slow runtime. Writing servers requires attention to performance and reliability, which javascript is very poor at. If you want to make a toy service and don't care about any of this, go ahead and use your favourite language. But when you want to make something incredibly fast and reliable (like nginx), you'll need to consider another technology.

Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @11:32AM (#15090912)
>If you're better with screwdrivers, why struggle with a hammer?

Hammers and screwdrivers are not general purpose tools in the way that languages are.

For most things, most languages are just as fine.

It's not like JS is specialized in some very small niche by design -- like e.g. COBOL is.

>JavaScript has a painfully slow runtime.

I call BS. v8 is one of the fastest dynamic runtimes, at 2x of C or so for lots of tasks, and it totally obliterates Python, PHP, Ruby, and co in speed. And since some of the web's different properties are written in the latter 3, it's certainly not speed (which JS surpassed them far in) that's the issue.

>If you want to make a toy service and don't care about any of this, go ahead and use your favourite language. But when you want to make something incredibly fast and reliable (like nginx), you'll need to consider another technology.

Nobody writes "nginx" in JS.

They write the kind of APIs and apps and services that people also used to write in PHP, Python, Ruby, Go and whatever lang.

Re:JavaScript is Eating the World by rootlocus on Thursday August 24, 2017 @03:44PM (#15093361)
> I call BS. v8 is one of the fastest dynamic runtimes, at 2x of C or so for lots of tasks, and it totally obliterates Python, PHP, Ruby, and co in speed.

Any proof for this?

EDIT:

According to "The Computer Language Benchmarks Game"

JavaScript fares pretty well against Python [1] or Ruby [2] but not really that great against C [3] or Java [4] in the CPU intensive benchmarks.

1 http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

2 http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

3 http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

4 http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @05:25PM (#15094194)
>JavaScript fares pretty well against Python [1] or Ruby [2] but not really that great against C [3] or Java [4] in the CPU intensive benchmarks.

Considering is a non-static, totally dynamic language, with all kinds of dynamicity in it, it does totally fine. 10x to 30x faster than Python, Ruby etc, and 3x to 5x slower than C/Java is totally fast.

Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @02:49PM (#15092867)
> It's not like JS is specialized in some very small niche by design -- like e.g. COBOL is.

Uhh, what? You don't consider "programatically manipulate the DOM in the browser" to be a niche?

Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @05:21PM (#15094164)
There's nothing about JS as a language meant specifically to "programatically manipulate the DOM in the browser".

Anything it does related to that is just simple library code and methods on the "document", "element", etc objects -- and that's only when run in the browser where those are available (automatically "imported" let's say). Node doesn't even have the "document" object.

Re:JavaScript is Eating the World by pier25 on Thursday August 24, 2017 @03:24PM (#15093189)
Accessing the DOM is not really part of the language specification, but the browser API, no?
Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @04:16PM (#15093677)
And the "Browser API" was invented to do what, exactly? And by what mechanism was said API exposed to developers? And whose cocktail napkin was the specification written on?
Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @05:23PM (#15094179)
>And the "Browser API" was invented to do what, exactly?

Whatever it was inveted to do is totally irrelevant, as the "browser API" is not Javascript the language/syntax but just an API (library/module).

In fact you could trivially implement it in all kinds of programming languages.

Re:JavaScript is Eating the World by wolco on Thursday August 24, 2017 @06:34PM (#15094645)
Maybe against php 4. PHP 7 is much faster
Re:JavaScript is Eating the World by coldtea on Friday August 25, 2017 @03:17AM (#15096777)
It's just about 2x as fast as PHP5.

JS JIT were already many times faster than PHP5. There's no comparison to the complexity, quality, resources and top-notch teams in play in JS JITs (just consider the vendors making them: Google, Apple, Microsoft and Mozilla) and PHP.

Re:JavaScript is Eating the World by tchaffee on Thursday August 24, 2017 @03:24PM (#15093185)
> If you're better with screwdrivers, why struggle with a hammer?

Not a great analogy. A more accurate analogy is switching from one very big toolbox to another very big toolbox. If you are used to one and know where all the tools are, and they have been used so much that the wood perfectly fits your hand, then it's just going to take some time to get used to the new toolbox. I'm not saying it's a hard rule and you should never consider another language. I just answered the question of why someone would want to use javascript on the backend. It's not the only factor, but it's a factor.

Re:JavaScript is Eating the World by exo128 on Friday August 25, 2017 @01:19AM (#15096290)
Going further with the toolbox analogy...

Imagine we have carpenters and brick layers. Two distinct jobs that maybe have some overlap of tools.

We decide that we have a lot more carpenters than brick layers, so we'll take a carpenters' toolbox and add a few brick layer inspired tools to it (but they're not necessarily the same, and some of the tools that can overlap maybe aren't quite as specialized, nuances, nuances, etc.).

Now, we can tell our managers that our problems are solved. All of our carpenters can now do masonry work.

The root problem of all of this mess is that both of these domains are different. Problems and solutions in the front-end tend to be different than in the back-end.

Management is sold on this "everyone is an interchangeable cog now" fantasy they have been chasing for decades and crappy decisions are made. We end up with most developers not really learning at least one of the areas of the full stack very well (and not learning both if they are really striving to under-achieve...).

Note: This same thing happened in Java before NodeJS, but in reverse. Back-end developers refused to really learn web development and so we ended up with misguided solutions like GWT and virtually every other high level Java web framework/library.

Perhaps I haven't run into the right people, but mostly my experience with other JavaScript devs is they don't even know the fundamentals really (they don't understand scope rules in JS, they don't really understand weak typing, they don't understand JS is single threaded, they don't understand closures very well, etc.). I don't know if this lack of understanding is due to a lack of experience programming at all, or just not really learning JavaScript (many non-JS devs are forced to learn enough JS to get the front-end working -- or at least seemingly working).

The thought of lowering the bar on development even further is frightening (Johnny did some web development last year, I'm sure he can transition to writing our back-end API since he knows JS). I'm all for anyone learning and improving as a developer -- and sharing in my passion. What I hate is this false confidence more and more people seem to have with everything and the problems it causes (they don't bother to learn the tools they have or the tools that came before them, they are too lazy to learn a new language/framework/library, and they have extreme NIH syndrome).

Re:JavaScript is Eating the World by randiantech on Thursday August 24, 2017 @09:26AM (#15089871)
Javascript as a language and ecosystem has evolved quite dramatically during the last years. Its not perfect though: it lacks features and ecosystem is still not in the level of maturity of other platforms, but is definitely going in the right direction. Regarding the single threaded server, its an architecture used before JS exists, and used by many other platforms/systems. Just to give you an example, Nginx workers are single threaded.
Re:JavaScript is Eating the World by johannes1234321 on Thursday August 24, 2017 @09:34AM (#15089945)
In Nginx you're not doing computation, just passing IO thru between file system, external processes (i.e. PHP via fpm) and the network. If Nginx ever is CPU bound there's something bad happening.

As I mentioned PHP: In PHP each worker is single threaded, too, but you can scale by having more workers in isolation.

Re:JavaScript is Eating the World by alayek on Thursday August 24, 2017 @09:38AM (#15089985)
You've hit the bull's eye! Yes, and you're also not supposed to do much computation in Node JS code.

Some addition, subtraction is fine. But Array iteration, JSON encoding-decoding and similar CPU bound tasks could block the event loop.

You can perform them asynchronously, or forward the request to some remote service that's better at doing these computations for you and return results (maybe some service written in Python or a database)

Re:JavaScript is Eating the World by TrickyRick on Thursday August 24, 2017 @09:47AM (#15090055)
What computations do you do in a webserver which hosts a REST API? Most of it is simple CRUD connected to a database, possibly with an auth layer on top, which is pretty much what you describe, passing IO through to a database and back.
Re:JavaScript is Eating the World by falcolas on Thursday August 24, 2017 @09:57AM (#15090129)
Compression, hash computation, regular expression routing lookups, parsing text, building and serializing datastructures, reading and writing caches; I could go on.

Sure, JavaScript (and Ruby and Python) are usually fast enough with modern hardware - but we can't pretend there's no cost.

Re:JavaScript is Eating the World by jdc0589 on Thursday August 24, 2017 @10:53AM (#15090557)
deserializing data structures is a great example. JSON.parse is SLOW. all it takes is a bit of bad code that doesn't do any checking of input size/etc... and if an authoritative source starts sending larger payloads than usual, your node process is horked. Granted, that's not a problem remotely specific to node, it just has a bigger effect in a node env.
Re:JavaScript is Eating the World by flavio81 on Thursday August 24, 2017 @10:56AM (#15090589)
> Most of it is simple CRUD connected to a database

If my apps were that way, i could have replaced my team with 20 well-fed monkeys.

Re:JavaScript is Eating the World by tisdy on Friday August 25, 2017 @12:08AM (#15096050)
Honest related question:

Does HN think putting 2-15KB JSON blobs in a Postgres DB running on Docker on a router is a good idea? Oh, and the table stores log data, so there's about 2 million rows after 5 days uptime. What do you think?

EDIT: This was not entirely related but it goes to the notion that it seems like a lot of myopic decision-making has somehow become even more acceptable and I would say this leads to dumb situations as above, and Node.

Re:JavaScript is Eating the World by hyeomans on Thursday August 24, 2017 @12:00PM (#15091199)
I had this same idea until I found about: http://openresty.org/en/ https://github.com/Mashape/kong/

Making a full API on nginx via lua sounds crazy but it appears that people do it.

Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @02:54PM (#15092911)
PHP isn't exactly the best alternative to compare node to; it was pretty much designed specifically to live in an Apache request-response cycle. It's not hard for most things to beat it in contexts outside the one it was intended for.
Re:JavaScript is Eating the World by mattmanser on Thursday August 24, 2017 @11:54AM (#15091140)
I don't think it actually is going in the right direction, they've screwed up loads of things.

Things like getter/setters and object initializers. And don't even get me started on Web Workers, which basically seem to be dead on arrival. The Web Workers design is so shockingly bad and not fit for purpose that I don't understand how anyone signed off on it.

Some bits of the new js are in the right direction, and those are the things that people talk about and are getting used, but lots of things were definitely not.

Re:JavaScript is Eating the World by coldtea on Thursday August 24, 2017 @11:25AM (#15090849)
>The more time goes by the more I feel crazy for missing whatever would motivate people to use js for anything more than is strictly necessary. Single threaded server???

So, like Nginx's model? Or 99% of Python servers?

You can still run multiple processes...

Re:JavaScript is Eating the World by 52-6F-62 on Thursday August 24, 2017 @01:07PM (#15091898)
Yes, I'm surprised nobody has mentioned child processes or the Cluster module.

https://nodejs.org/api/cluster.html

There are a lot of knowledgable people commenting, but it's starting to seem like they haven't familiarized themselves with the tools available within the NodeJs base.

To another point, I could put the time into writing a server and back end application in Go or Rust or C++ or whatever, but it would take (at least me) 10x as long to build out the application I need as it does to pull express into a project and build out a server, back end computations, file manipulation, authentication, and roll a MongoDB store with a fully-fleshed out front end (even if it's not so stylish).

Mind you I work in an enterprise environment where these kinds of things are required to serve maybe twenty people and run on a single multi-cored machine at any given time and not tens of thousands users.

It's a fantastic tool that works from small to mid-large projects, and would serve as an excellent prototyping and MVP-dev environment for even the naysayers who are probably more skilled than I am in other areas.

Re:JavaScript is Eating the World by gozur88 on Thursday August 24, 2017 @01:45PM (#15092301)
>You can still run multiple processes...

The problem with Node is it's unsuitable for a whole class of server applications - you're going to run into trouble whenever you need to maintain serial access to a single resource. Whereas in Java you'd have some sort of token that gets "taken" by different threads, there's no clean way to do this in a multiprocess Node environment.

Re:JavaScript is Eating the World by sametmax on Thursday August 24, 2017 @09:28AM (#15089886)
Exactly. We got cancer on one major organ, why spread it ?
Re:JavaScript is Eating the World by sigzero on Thursday August 24, 2017 @09:38AM (#15089979)
Too late! cough Electron cough