At some point, JavaScript got good(jonbeebe.net) |
At some point, JavaScript got good(jonbeebe.net) |
In that regard JavaScript is a lot like C++. You can write pretty good C++ if you know what you are doing but the old ways are still possible and haunt you in legacy code.
However, with JavaScript you have to avoid the old/outdated language constructs, and some warts need to remain, since browsers still need to support old websites. Perhaps in the future we can specify "ECMAScript version" (similar to perl) so old stuff can be thrown away and the VM can optimize without having to worry as much about backwards compatibility.
There is some hidden assumption this language should reflect some other language a given programmer is formerly trained in and then disappointed when JavaScript is not their favorite pet language. Further interesting is that there is no interest or investment in formal training in JavaScript, just assumptions and failed dreams.
In that spirit when people say getting good I usually take that to mean looking more like Java, C#, or whatever.
ES6 'let' has very similar semantics to perl's 'my' and the absence of an equivalent elsewhere has always made me feel like I was missing a limb.
There's currently a proposal (which I think looks likely to succeed) to add a 'do BLOCK' syntax to ES6 as well, which is (now I get sane scoping) the top perl feature I miss All The Time when writing JS, and I can't wait.
(in the cases of both ruby and python the function scoping seems to be a deliberate choice rather than an omission and I just Do Not Understand how it doesn't bother people more)
Regarding your last comment about Ruby and Python. I've been thinking about this for a while and I think a lot of the hate people have towards JavaScript is due to the fact that (being the only "official" web language) lots of people were forced to use it without any other choice, which adds a lot of resentment.
On the other hand, Ruby and Python are deliberate choices of which there are many options. People who choose to use it love it, and people who don't can move onto something else. It's not the same with JavaScript. If you want (or need) to do frontend development, you had to use JavaScript.
I observed this with Lua community in the past. I hardly ever see anything negative about it, but it has its own oddities (such as 1-based indexing, global by default variables) and is in a lot of ways similar to JavaScript being a prototype-based language (the only other one that I know of actually).
my $thing = do {
my $intermediate_1 = foo(...);
my $intermediate_2 = bar($intermediate_1, ...);
baz($intermediate_2);
};
type code is something I use quite a lot to be able to name the intermediates while keeping them from escaping into the containing scope. So let thing = do {
let intermediate_1 = foo(...);
let intermediate_2 = bar(intermediate_1, ...);
baz(intermediate_2);
};
is going to make me a very happy camper.My other major irritation these days is that 'let' is a statement in JS, whereas 'my' is an expression in perl, and I'm very used to writing
if (my $token = $user->admin_token) {
...
}
and similar constructs. In JS currently I have to write let token;
if (token = user.admin_token()) {
...
}
(and wrap that entire construct in its own block if I don't want the 'token' variable to continue to exist afterwards, which generally I don't)The javascript-viable version of that is probably to have a special cased 'if let' just like 'for let' was added already.
I'm unaware of a proposal for that - yet.
Though the 'match' proposal currently in flight IIRC assumes 'do BLOCK' is available, and that will probably give me something sufficient to stop grumbling about that one.
(learning lisp, then applying the same "lexically scope as tight as possible" aesthetic I developed there to my perl code, then trying to use ... pretty much anything else ... has been an irritating experience on occasion ;)
It's close though.
Reducing module to module call overhead is important for being able to split larger WASM applications without needing to do so by performance boundary rather than logical or other optimised boundary calc. Doing this properly probably means a proper dynamic linking approach or something but I'm no expert.
DOM API is self explanatory. The whole point of the web is the unified presentation layer but being forced to talk to it via a bridge sucks. Once it's done then WASM/DOM becomes GTK on steroids.
I spent four years building an in-browser digital ad auction manager in JavaScript that truly bent my mind and that also delivered millions of dollars in ad revenue. You would think I would come away from that experience thinking "I know JavaScript", but I instead I came away thinking "That was hell, I never want to work in JavaScript again".
I worked on that project over the time period when ES6 was introduced and also later transitioned everything to TypeScript. I agree that things got better, but I still think that JavaScript is pathetic.
Why would anyone use JavaScript when there are web stacks that JavaScript-free? You can use Flutter on the front end (people rave about how nice it is to program in Dart and Flutter) and there are also options like Elixir/Phoenix/LiveView and HTMX, which allow you to build modern web apps without messing with JavaScript.
I can't stand the fact that every other tech startup is using Node on the backend.
Everything can be so much simpler and better and nicer, but it is not.
I decided to go with Nestjs since it sets up somethings for you out of the gate. I’m still not fully happy with that decision, but it is what it is. Btw, I don’t even know how to write tests for any of the code I wrote. I’m still figuring that out. We just needed quick and dirty code that we can test in real world. But we’re happy with this, admittedly shitty, backend for now while we have been testing it with our initial audience.
So now I’m leaving heavily on the author’s side that the modern JS ecosystem and the language itself is pretty good. It still requires quite a bit of sophistication to understand what is going on, but it isn’t a nightmare inducing mess that popular programming culture makes it out to be.
I don’t think a complete newbie would have been able to do what I’ve done over that last few months. You still need to check a lot of your expectations of the language and be careful. But quite a lot about this ecosystem and the tooling available is undeniably impressive.
I would just advise people not to fall for the “backend elitist” mentality that is so prevalent in the discourse and actually try things out for themselves.
I come from a Java background and have mostly done server side until a eight years ago when being in charge of a startup meant I could not be picky about what I did and had to be able to do all of it (web, server, devops, etc.). That started with me inheriting a javascript code base. As javascript codebases go, it wasn't horrible but still pretty mediocre compared to what I was used to. No tests, obviously. And a lot of very verbose gibberish dealing with promises and what not.
I took the opportunity to learn typescript and migrated quite a bit of javascript code to that. I like typescript; it's great. But it is a bit of a compromise in that all javascript is valid typescript. Meaning, you inherit all the ugliness and weirdness with typescript and you need to be careful with how you use it. But it's a fine language and having a decent static type checker just wipes out whole categories of bugs that I don't need in my life. I found plenty of those migrating the Javascript code. Or rather the compiler did. I just fixed them as it found them. Cheap success IMHO. The downside of migrating javascript code is that a lot of it is still javascript and you end up either replacing a lot of its ugliness or not touching it until you have to because, for example, it's obviously broken or not right.
Fast forward a few years and another startup and I had a frontend developer whose only experience was Kotlin on Android. And I needed a webapp in a hurry and had no budget for bringing in re-enforcements. I considered doing react and typescript and training the person up. But instead, we evaluated using kotlin-js. Much to my surprise, this was actually pretty good. I had been using Kotlin server side for a few years and it obviously worked well on Android. But kotlin-js on the web felt risky. Yet a few weeks in we were getting kind of productive. We had integrated a few javascript libraries, picked a ui framework (fritz2) and my frontend developer was getting quite productive with it.
That was three years ago. That app still exists. As a technology choice it's been great. It was definitely a wild ride though in terms of being an early adopter. We were dealing with a rapidly evolving library ecosystem (kotlin multi platform), compiler bugs, a complete compiler rewrite in several steps (2.0 RC2 was released a few days ago), and a lot of other things. However, life is pretty good doing kotlin-js these days. If you want a break from typescript, it's well worth checking out. It would probably be considered cutting edge or risky in a lot of places. But it definitely worked well for us.
You can use react with kotlin-js btw. Lots of people do this.