News for hackers. Stuff that matters.
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.