News for hackers. Stuff that matters.
Re:JavaScript Is Weird by andrewfromx on Sunday August 13, 2023 @12:06PM (#37111186)
this is the reason I pick a language OTHER than js for the backend. Why oh why did the whole world decide nodejs sever side js was a good direction? For the frontend I get it. Unless you are going to mess with WASM files you need js.
Re:JavaScript Is Weird by danShumway on Sunday August 13, 2023 @12:32PM (#37111459)
Knowledge transfer, context switching, the stuff you already know. But there's also an interesting non-JS reason that's gotten forgotten because the serverside landscape has changed so much since the early 2010s. Node very heavily popularized single-threaded asynchronous request handling (ie, not starting up a thread for every request that came into the server).

Of course there is nothing about Javascript that means it specifically as a language is essential for that pattern, but I remember hearing talks from Netflix employees and industry advocates about how much Node had improved their performance; I remember industry people coming to my college and talking about single-threaded serverside code and saying "you all need to check Node out."

And there are downsides to asynchronous code (callback hell was the obvious downside that got brought up a lot before `async` arrived in the language) -- but I remember among especially younger serverside developers this trend of people saying, "Node is just faster. That's why you use it, because it's just straight-up more performant than what you're currently doing." And I understand serverside devs from other languages can at this point jump in and say that it's not, that the single-threaded model is possible in other languages, that there are downsides to the single-threaded model, that Node doesn't do it well, whatever. I'm not arguing the point, I'm just describing the cultural shift I saw.

All of the conversations about sharing code happened too, but I remember having conversations where people talked to me about jumping to Node specifically because Express was single-threaded and because it could handle more concurrent requests than other popular server architectures that they were familiar with. And I suspect that it gave the ecosystem a lot of momentum.

Node's original purpose was in part an experiment to see if single-threaded async request handling would be able to handle large numbers of simultaneous requests. My somewhat-limited memory of the conversations that were taking place back then is that running the same language clientside and serverside was just the icing on the cake. The big reason people were excited was because Node was single-threaded.

Re:JavaScript Is Weird by jiggawatts on Monday August 14, 2023 @09:12AM (#37120653)
> single-threaded serverside code and saying "you all need to check Node out."

When Node started to become a thing, Java and C# has already been doing multi-threaded web servers for about a decade.

Oh, and C# already had support for async programming too!

Node become popular in part because Silicon Valley just doesn't seem to be aware of anything that exists outside it.

Re:JavaScript Is Weird by danShumway on Monday August 14, 2023 @09:50AM (#37120994)
> Java and C# has already been doing multi-threaded web servers for about a decade.

Node was single-threaded async, not multi-threaded. The entire point was to not spin up multiple threads and to rely on the event loop instead.

> Oh, and C# already had support for async programming too! Node become popular in part because Silicon Valley just doesn't seem to be aware of anything that exists outside it.

> And I understand serverside devs from other languages can at this point jump in and say that it's not, that the single-threaded model is possible in other languages, that there are downsides to the single-threaded model, that Node doesn't do it well, whatever. I'm not arguing the point, I'm just describing the cultural shift I saw.

Right or wrong, you can go back and look at forum posts even only 6, 7 years ago and you'll see people asking about single-threaded performance and asking how Node manages to scale if it's single-threaded. A lot of developers at that time got introduced to single-threaded event-based asynchronous server programming through Node.

I'm not telling you that Node should have won, I'm telling you one of the reasons why it happened to win. Here's Dahl's original slides presenting Node in 2009: https://s3.amazonaws.com/four.livejournal/20091117/jsconf.pd...

Immediately the first thing he's talking about is not unity between the front-end and backend language or sharing code. It's "I/O needs to be done differently." That's what people were talking about back then.

Re:JavaScript Is Weird by danShumway on Monday August 14, 2023 @12:30PM (#37122972)
Edit: here's the actual presentation, not just the slides: https://www.youtube.com/watch?v=ztspvPYybIY

What's interesting about this talk is that Ryan doesn't even mention Javascript at all (other than briefly to say that NodeJS is built on it) until nearly 13 minutes into the presentation. And it's clear that he's using Javascript as a means to an end -- he's going with Javascript largely just because Javascript by default has a single threaded event loop that every JS programmer had to learn to work with it.

So he brings up going with JS because JS programmers are used to callbacks already -- and then roughly 2 minutes later he immediately moves back to talking about I/O and request handling again. Very little of his presentation is about Javascript beyond an aside of "JS already does this and JS programmers are used to it, so we might as well go with that and try to copy JS conventions." He almost spends more time talking about common SQL libraries than he spends talking about JS.

Re:JavaScript Is Weird by mohbk on Sunday August 13, 2023 @12:18PM (#37111314)
the website is 90% problems of very stupid implicit type conversion, and 10% valid floating number behavior that exists in other languages too (0.1+0.2, NaN a number)

I agree using plain JS anywhere is not a good idea, but Typescript (or js with ts annotations) is often ignored when it does a very good job of catching most of these issues, while offering a very flexible type system in a more mainstream paradigm

Re:JavaScript Is Weird by deergomoo on Sunday August 13, 2023 @12:26PM (#37111395)
Cause people wanted to write their front-ends and back-ends in the same language, for various reasons (code sharing, economics of hiring developers, etc).

My issue with JS (particularly but not exclusively server-side) is less that it has some weird aspects and more that its built-in functionality/standard library is incredibly barebones in many respects. IMO that’s the main reason why it’s considered normal in the JS world for a project to pull in hundreds/thousands of largely un-vettable dependencies.

Re:JavaScript Is Weird by jakelazaroff on Sunday August 13, 2023 @12:30PM (#37111427)
This is the reason you don’t pick JS for the backend? I’ve been using JavaScript professionally for over a decade now and I’ve literally never needed to write +!![] or “” - - “” or even a single one of these esoteric edge cases. (Except the floating point weirdness, which is an issue in basically every language.)
Re:JavaScript Is Weird by andrewfromx on Sunday August 13, 2023 @12:36PM (#37111497)
no i mean the fact that JS was invented in 1995 and isn't well designed because we didn't know what we know now. I'm a professional golang developer and it just feels obvious to me when writing go; wow, this language was well thought out and fixed a lot of mistakes from 1995. (In a way that TypeScript doesn't even come close)
Re:JavaScript Is Weird by jakelazaroff on Sunday August 13, 2023 @03:10PM (#37113168)
I really like Go, and I tend to prefer it to JS for server-side stuff, but when I use it there are a lot of things I miss about JS:

- Error handling is onerous; I write a lot of functions where most of the lines are just checking for and returning `err`

- No anonymous structs, and it’s really awkward to define structs inline

- Dealing with collections is really verbose; I guess since generics dropped I could handle this in userland, but it’s not idiomatic

etc etc. No language is perfect!

Re:JavaScript Is Weird by andrewfromx on Sunday August 13, 2023 @05:12PM (#37114555)
I think u might like my "go on rails" framework:

https://many.pw/sd/

I make heavy use of map[string]any vs structs. I also find the right balance of checking err vs just making it _

Re:JavaScript Is Weird by WorldMaker on Monday August 14, 2023 @05:21PM (#37126959)
JS was better designed than people give it credit for or it wouldn't have lasted anywhere near as many decades without being replaced by something else.

JS has also had a lot of its "mistakes" fixed since 1995. It does so in a backwards compatible way and it isn't always obvious how much progress has been made, but it has never been a static unchanging, "unfixed" language.

(Personally, I'd much rather work with JS on the backend than golang. Golang looks to me like a throwback to the 1970s that misses good language design ideas from the 1990s. I understand some of why it has become popular, but there's so much bad design in that language that upsets my nausea.)

Re:JavaScript Is Weird by rr808 on Sunday August 13, 2023 @12:11PM (#37111229)
I personally do not know much about JS other than some light projects, but I have worked on an application that was C# both front and backend and the productivity was higher than anything else I've worked on. Using the same language, same tools, same developers, same job interviews was great. I'm thinking of doing back end JS for this reason.
Re:JavaScript Is Weird by foooorsyth on Sunday August 13, 2023 @01:03PM (#37111785)
I think Microsoft’s web stack is underrated, and was perhaps a factor there as well. I’ve seen unusually fast products written in the “dreaded” ASP.NET. Visual Studio is a much more powerful IDE than vim/VS Code, and imo C# is a much more scalable language that vanilla JS. Typescript bridges the gap pretty well.
Re:JavaScript Is Weird by joshmanders on Sunday August 13, 2023 @12:37PM (#37111503)
> this is the reason I pick a language OTHER than js for the backend.

You choose against a language because of code that any sane person, which I hope includes yourself, would never write intentionally?

Weird flex, but ok.

Re:JavaScript Is Weird by andrewfromx on Sunday August 13, 2023 @01:45PM (#37112219)
Re:JavaScript Is Weird by paulddraper on Sunday August 13, 2023 @12:22PM (#37111354)
Node.js is popular is precisely because browsers are popular and JavaScript is the language of web browsers.

Reusing code, tooling, training is meaningful.

Every language (Java, Ruby, Go, Bash, whatever) has quirks. JS may have more than others, but it's not alone.

Re:JavaScript Is Weird by esafak on Sunday August 13, 2023 @12:36PM (#37111499)
Does anyone still call it "isomorphic"?
Re:JavaScript Is Weird by devbent on Sunday August 13, 2023 @12:24PM (#37111367)
Like typescript, which is an amazingly good language with an absurdly powerful type system that is easier to learn that competing absurdly powerful type systems!
Re:JavaScript Is Weird by moffkalast on Sunday August 13, 2023 @12:14PM (#37111266)
The fact that JS can be this stupidly wacky yet still be so enjoyable to work with that nodejs is as popular as it is says more about other languages than about JS, I think.
Re:JavaScript Is Weird by thfuran on Sunday August 13, 2023 @01:03PM (#37111792)
Are you sure people are using it because they enjoy using it?
Re:JavaScript Is Weird by moffkalast on Sunday August 13, 2023 @02:50PM (#37112917)
Yes, I'm pretty sure. In my and my friends' experience at least. As long as the codebase is of manageable size it's one of the most laid back languages out there, letting you get shit done without having to write pages of boilerplate or being lectured by a compiler. The level of abstraction is just right for the current hardware too.

I'll probably get flamed for saying this, but having all objects be hash maps that can be extended or edited at any point and be simultaneously dumpable and loadable into JSON with one line was an unfathomably big brained move. Being able to just use the data you get from various sources instead of having to create an ad-hoc struct/object that perfectly matches all types and values (and ofc crashes immediately if a change is made on the other end) is so underrated. That's not even mentioning the native async support.