by ivanmontillam · 3y ago · 0 comments
One of the things that discouraged me from Front-end Web Development is JavaScript weirdness. It just has too many pitfalls and it's very hard to debug for a newcomer unless you study a proper JS course that tells you precisely all of these traps before you get burned. I've never found a programming language that didn't behave like I expected it on first touch, except for JS.
I am fully aware TypeScript exists, and there are transpilers where the syntax (modern ECMAScript) and rules are more appropriate to current times, but these aren't "native" of the browser. You must still transpile to the hazardous old JS. I know transpilers avoid many of these pitfalls, but I cannot avoid feeling like I'm building a skyscraper in quicksand.
The hard thing about talking about this exact topic it's that I'm sure my comment will trigger negatively a ton of developers, because talking about JS like this it's going to feel like I've insulted a cult. Let me be clear this is not my intention. I come from the static-typed programming languages world, so I have a preference for my programming to be the most correct.
WASM to me provides this solid foundation, if only (big IF) we manage to create a browser where the main execution virtual machine is not a JS one. I've dreamed of a browser that supports multiple stacks, instead of the HTML/CSS/JS monopoly. For instance, why'd be too hard to think about something like HTML/CSS/Python?[0]
JS has been a discourager to me career-wise, and I'm doing great in Back-end Web Dev, but I'm pretty sure I'm not the only one feeling this way about it. The web should be more accessible in this sense.
--
[0]: I am aware of the existence of Brython: https://brython.info/, but it's not my point, that is still Python-over-JS.
Just FYI this line of argument is called “poisoning the well”. Definition from Wikipedia:
> a type of informal fallacy where adverse information about a target is preemptively presented to an audience, with the intention of discrediting or ridiculing something that the target person is about to say.
It is not conductive to a reasoned discourse about a technical topic.
Although it was poorly phrased, what GP meant to say is that they weren't trying to intentionally offend anyone's sensibilities, they were just expressing their sincere opinion on a subject.
The GP described opposition to his argument, before it was presented, as coming from triggered members of a cult.
If this is not poisoning the well, what changes to his argument need to be present for it to cross over the line?
How much more clear does it need to be?
And to rub salt into the wound, he then went on to describe his preference as "the most correct".
I wonder what he primarily programs in.
Javascript is terribly inconvenient and has tons of weird edge cases ("semicolons are optional except for these three edge cases", scope switching through using, the unpredictable type conversions) but the rules aren't that hard to write a transpiler for. Transpiling another language into JS will probably leave some optimisations on the table (by reimplementating methods in a way another language expects rather than calling the native Javascript API) but at least it has the normal API to rely on.
WASM is like Docker; it works on my machine, I can't get it to work on your machine, so we'll ship half of my machine and call it even. You're shipping standard libraries and JSON parsers to a browser as if you're pushing code to a bare metal server.
Javascript isn't a hard language to learn and neither are HTML or CSS. What I see many WASM people want to do is write browser code without ever needing to learn how the browser works. That's a terrible idea that will only end in either bloat or broken abstractions. "Let's make backend devs do frontend" is how we ended up with Java applets everywhere, which barely worked inside the context of a desktop browser, let alone on touch screens and phones.
There's a reason "native" desktop development has become "run an outdated copy of Chrome with some OS glue", and it's that web development is easy compared to native frontend development, especially if you target multiple platforms. WASM isn't going to turn backend developers into frontend developers overnight, you'll be stuck learning new frameworks and barely usable tooling regardless.
Just use JS, it's inconvenient but much a much better option than the proposed alternatives.
I fully understand the reluctance or just sheer annoyance of having to set up a toolchain just to end up with JavaScript. I've written an absurd amount of JavaScript since 1995. And yes, it is quirky, and awkward, and at times seemed downright ridiculous. ES6 at least was somewhat of a paradigm shift towards normalcy. Granted, JavaScript was created "in 10 days" and then simply became the de facto language of the web.
But after I started working with TypeScript, and enforcing linting rules through ESLint, and working in a proper IDE for it like VSCode, there is simply no going back. And it's not just the development that is so much better. With tools like webpack you also easily get tree-shaking, bundling, and minification, which are all good things for the users.
For very small sites with a single developer, sure you can just write JavaScript and call it a day. But anything even slightly beyond that and I would take the small amount of time to setup a build environment. It's not that difficult, and once it's set up properly it should stay out of your way and help tremendously.
I'm full stack lead on an enterprise Angular project that happens to require all of this stuff, but I would use it going forward for many less complex, non-SPA projects as well.
After 20+ years I don't necessarily loathe working on the front-end anymore.
That's not to say I didn't have to be pulled kicking and screaming into this world at first, while yelling "get off my lawn!". That may have been the case.
WASM simply is a better compilation target. More general purpose, easier to optimize, more compact, can load incrementally, etc. If you are going to compile your code anyway, you might as well use a proper compilation target if you have the choice.
More generally, I think WASM is starting to challenge the whole "there can only be DOM/CSS/JS" thing that has held web developers back for two decades. It was fine when that was the only thing that worked but there's a reason mobile developers, game developers, etc. prefer native: the web sucks. There has always been this creative tension between what designers want and what the web can do. We used to have things like Flash, Shockwave, and Silverlight. HTML 5 has largely failed to replace those. We deprecated the plugins for security reasons. But we never got a decent replacement.
With WASM there's no good reason left to keep on preferring DOM/CSS/JS. It's there if you want to, but there are some alternatives now. In its current state, that still requires things like C++ and Rust.
But WASM is maturing rapidly. There are a bunch of things behind feature flags in browsers (like the new GC stuff) that will level the playing field once those flags get removed. From there, it's mainly a matter of UI frameworks and tool chains that need adapting. Jetbrains is actually targeting wasm with compose multi platform. It renders to a canvas. Currently experimental and it only works if you set some feature flags on your browser. But it allows for portable UI development with Compose and allows you to target Android, IOS (alpha release), Desktop (jvm), and soon Web via wasm with the same codebase. There are probably other UI stacks that might soon start targeting web. Blazor of course was an early adopter but it ships its own GC and that makes for a bit chunky apps. And of course there is a wasm based replacement for Flash.
HTML 5 is no longer the only game in town. It will have to compete on merit now instead of merely holding a de-facto monopoly.
We're going to need a pretty advanced WASM decompiler suite built into the browser before I'll accept it as just as opaque as Javascript.
I despise the WASM web application platform and its blatant <canvas> abuse. It's building a browser inside of a browser to save developers time, and every time web pages become slower and worse to use because of it. React (Native) did cross platform app+web development years ago without downloading several megabytes of executable blobs for every page you visit.
WASM is just Java applets and Flash embeds, but invented for the fourth time. They have the same problems and will inevitably cause the same slowdown and headaches a few years from how. The only difference for developers is that you can now use Rust to write them and that your users can't turn off loading your binary blobs.
https://docs.google.com/document/d/1oDBw4fWyRNug3_f5mXWdlgDI...
Some of the outstanding issues still to figure out:
• Autofill. Users want browsers to be able to autofill/autocomplete things, but without that leaking personal data to sites unexpectedly (i.e. the content needs to look present but can only actually be present from the API perspective once the user has confirmed they want it).
• Secure composition/iframes. Essential for anything with ads, social buttons and some other use cases. Yes, you can define ads as being out of scope but then a lot of people won't bother to learn your new framework because it will be less general.
Ultimately, the technical problems are severe enough that WASM frameworks will be of limited use, quite possibly forever. It's just not in the interests of browser makers to disintermediate themselves like that. You can get a long way by blending DOM widgets with other stuff though.
No one was held back, people keep choosing the web because it's consistently better.
What I think is crazy is this drive to take something that is working great (the Web), and then jam in an approach that has already failed multiple times. We already tried several iterations of binary-heavy, non-transparent, non-searchable, non-web-native, second-ecosystem application platforms including Java Applets, Flash, Silverlight, etc. They had a chance and users rejected them.
If you think the web sucks, then by all means, I encourage you to make a compelling alternative. If it really is better then people will use it. But maybe don't try to spoil the working recipe of HTML/CSS/JS, especially if you don't fully understand the reasons why it keeps winning.
It's not consistently better. It's just marginally easier to develop simple things for.
> They had a chance and users rejected them.
Users rejected them because they were slow, bloated, and didn't play nice with a lot of things. Fast-forward to 2023, and users have embraced mobile apps (and not mobile web/PWA crap that we're told is about to get just as good as apps any time now).
> If you think the web sucks, then by all means, I encourage you to make a compelling alternative.
It's already there. It's called apps.
Your position is that Flash didn't compete (and lose) on merit?
After that, security concerns lead to browsers eventually deprecating their plugin support. But it started with Flash getting a huge access denied on mobile, courtesy of Steve Jobs.
So, Flash became a lot less popular after that and Apple and Google successfully transitioned a lot of that stuff to their native mobile SDKs. That's why you have lots of games on IOS and Android and not a whole lot on the web these days. HTML 5 is hopelessly clumsy for that sort of thing.
A lot of the stuff people did with Flash is of course technically doable with HTML5 but mostly it seems designers shy away from doing those things because it's too hard.
Wasm is going to open up a lot of native and mobile SDKs for the web. And the web of course also works on mobile. There might even come an end to Apple blocking non-safari browsers in their app store.
There's lots of times in my work when I will read minified JS code to debug a stack trace. Using the "Pretty Print" option it's not too bad. So I'm glad it's there.
Also transparency is not just about humans reading it, it's also about automatic scanning of the source, and in some cases automatic modification of the JS (for browser extensions or code analysis or etc). Those are useful things that are drastically harder using WASM.
The times when people "hacked" the JS of the websites they visited are long gone, and for nearly all web applications (which is what WASM is useful for, as opposed to simple websites) the code is already completely unreadable (even if it were not minified, I mean, you would probably need to spend weeks understanding what it's doing for non-trivial stuff)... it's even illegal today to alter websites you visit to use "hidden" features, depending on your jurisdiction.
Besides, WASM is not going to displace JS, it will just give people an option to achieve things they couldn't with JS alone.
Though truly no software is obscure enough, given enough resources (time and money). All software is open source if you care to look hard!
Not really, because open source has a definition and that definition refers to the form that the software was authored in.
In addition, there are homomorphic encryption methods which make it possible to completely obfuscate the SW function, practically speaking. You don't even have to go that far, just look at a typical LLM network.
(As an aside, I think it would be funny if someone implemented a game where Minecraft-like crafting functionality would be implemented through a one-way hash function. So no one could look up the recipes in the source code. Or an adventure game which would hash the input command and the world state to decode the resulting progress.)
Though I'm not clearly seeing why is that a challenge. From a security standpoint, browser security and compartmentalization is very strong. From a learning standpoint, many wheels will be reinvented (but that's true today even in a JS world, just check out npm registry).
This _should_ be gotten thanks to work on stack switching in WASM. As of the most recent working group meeting on this [0], it seems like V8 has made a good amount of progress on this. They published a thing back in January[1] on this, and hopefully if things go well and this is available across WASM engines then there will be one less "JS-ism" (everything async) that causes issues for transpilation.
[0]: https://github.com/WebAssembly/meetings/blob/main/stack/2023...
The fact is right now if the source language has a notion of blocking calls, the when compiled to a non-blocking target like WASM it currently has to do a bunch of tricks that outright makes things slower. WIth these improvements, those "blocking calls" can properly end up non-blocking at the JS layer, matching what we all know computers can do.
JS stuff is non-blocking because of the original sin of Javascript (we have to execute all the JS before we can render a page, since there can be some document.body = ... nonsense in there). This is incidental to the programming model, and not some deeper truth about how things should be programmed.
Case in point: non-blocking `async` code in Javascript ends up sometimes turning into blocking code for performance reasons in specific cases (when awaiting an already completed promise, notably). Jumping in and out of an event loop isn't exactly efficient either.
What a completely unnecessary thing to say in the middle of an otherwise reasonable post.
It's applies for many programming groups. Those like to live in their realm, one where that their language is the greatest and thou can't be spoken negative about.
Just try mentioning C++ to a bunch of Go programmers or Python to a bunch of Rust programmers.
Not to say there isn't crossover but it's all ironic really, as most languages were crafted from C.
Still I agree with your other comments, and in particular not being able to share caches in the browser is very unfortunate (but understandable).
Typescript is ok overall and the various frameworks / libraries used to generate a browser elements are really to my simple take not so much a language workaround than the best some very smart people have envisioned to build/update browser elements Well maybe in another language react hooks wouldn’t be so quirky
These existed. You could have used VBScript instead of JavaScript (Internet Explorer). Or, perhaps, you might have wanted to go all the way in the other direction, and use JavaScript syntax for your stylesheets, instead of CSS (Netscape Navigator, JavaScript Style Sheets aka JSSS). As for HTML, it might be possible to use pure XML styled directly with CSS or something like XML-FO, without having a XSLT which transforms it into HTML, but I don't know which browsers support or have supported that.
Can you share some examples?
Since this has nothing to do with JS per se and is a standard example to showcase the counterintuitiveness of IEEE 754 doubles, then does this mean that you have never worked with another language that uses IEEE 754 doubles? (And in what other languages do you find yourself typing "===", i.e. what would motivate you to type it out "on first touch", anyway—rather than "==", that is?)
The quiz is filled with other examples like "+!![]". Can you briefly explain what intent/expected behavior is associated with the mindset a decision to type this out in a program and how JS violates those expectations and would therefore would be better if only it could be changed?
Do you have some real-life examples of things you've personally encountered, rather than crazy examples that no-one would actually write?
WASM will be used in cases when performance and correctness is worth the extra effort. Libraries, components, etc. Js will glue it all together, like the Python of the web.
There is now a generation of developers equating front-end with web.
> ...but I'm pretty sure I'm not the only one feeling this way about it...
There are dozens of us!
I'd go further than that. There is now a generation of developers equating all of Software Development with Web.
The irony? They don't think their web browser, code editors, IDEs, operating systems, etc. are also software that someone developed. For them, it's like firmware that just magically appeared.
As a somewhat extremist on this front, I'd rather "the web" was still Gopher that shifted nice PDFs generated in LaTeX and 80 column formatted text files. And email was plain text only. And leave the rest to native apps on whatever platform you happen to like.
WASM is basically Flash but less shit.
Yes there are a few weird things around true/false evaluations and other syntax "gotchyas", but they take at most 5 minutes to grok the ones that actually come up in normal day-to-day coding, and many of the other things that people like to flag up (like scope in blocks/functions) are often the same in statically typed compiled languages too - there was a blog post from golang just recently about a "common mistake" around scoping of variables in loops etc for example (sorry cant find link). Don't even get me started on Python's weirdness.
What I am saying is there are many ways to shoot yourself in the foot in any language - you'll "get burned" in anything that you don't really understand. First-touch of rust without really knowing the language that well? First-touch of c++ without really knowing the language that well? Have fun not getting burned with those until you have studied a proper rust/c++ course that tells you precisely all of the traps. It turns out that you need to know about a programming language to use it effectively.
And for what it is worth, modern ECMAScript does not need a transpiler - it executes directly in the browser without any molestation. Typescript requires transpilation to javascript before execution, but you can get a long way without typescript if you want to without sacrificing too much besides types (and tooling these days for standard ECMAScript is excellent)
I think that maybe perhaps you are confusing javascript with browser-based frameworks like React? React and NPM are a total dumpster fire of awfulness, but they are not javascript.
I'd encourage you to give modern, native ECMAScript another go.