News for hackers. Stuff that matters.
Re:Brython: an implementation of Python 3 running in the bro... by bluedays on Monday July 19, 2021 @01:47PM (#27885345)
I'm hoping web assembly eventually completely replaces javascript. It would be amazing if we could theoretically compile any language down to be browser compatible.
Re:Brython: an implementation of Python 3 running in the bro... by gchamonlive on Monday July 19, 2021 @01:57PM (#27885440)
This is something that I wanted to hear more from people invested in frontend.

I work exclusively as a DevOps/DataOps/Backend engineer and have little contact with stuff running in the browser. I did, however, work with AngularJS back in the day, and although the framework itself didn't lend itself to nicely to productivity and simplicity, I believe that what I found most confusing was how unergonomic the browser environment itself was, from not dealing with a filesystem (and thus having to resort to tricks like transpiling and bundling) to the rather terse API, not having for instance a SQLite natively and not being able to enable something like this without bringing copious amounts of megabytes of extra javascript deps...

Is the browser environment becoming more dev-friendly with the adoption of WebAssembly? I ask that because, in my opinion, if the browser itself doesn't evolve, it doesn't matter which language we use, interacting with it will still be a hassle. All in all, it feels like the browser advanced a lot in technology for optimization and resource management, but not so much in becoming more user-friendly to the developer.

Re:Brython: an implementation of Python 3 running in the bro... by tmm84 on Monday July 19, 2021 @09:48PM (#27889303)
The problem was WebAssembly despite what people think isn't a JS replacement. WebAssembly isn't designed to go after DOM manipulation and the rest of the browser world (in short, think calculating physics and heavy number crunching instead of whether or not some input with id blah is blank). The best analogy I can give is this, imagine using Lua and calling of compiled code (C/C++/Rust/etc), this is the JS/WebAssembly way of doing things.

Does the web browser (an application for reading documents written in hypertext), need to evolve? Or, has the web browser been asked to do more than it should and we need a new type of application? So much of the internet is based around the fact that the basics of the web browser can't change (don't break the web!). If the basics can't change then maybe the need for a new standard where the basics fit the application is required.

Re:Brython: an implementation of Python 3 running in the bro... by dmos62 on Tuesday July 20, 2021 @03:24AM (#27890921)
The browser has been a system-within-a-system for a long time now. That's a pretty big problem, because it's inefficient computation-wise and has very low interoperability with the host system, which has big implications. The user also has sort of an upside: the browser, being isolated on the host machine, is very portable. And, maybe safer, but I'd argue against this point, because a monolith is too hard to audit; if you want security and correctness you need many small components, not one huge one. But, those are user problems. Big vendors enjoy non-interoperability, because it lets them do user lock-in and have monopolies. That's also why we hardly have medium-sized vendors: only gigantic and minuscule.

If I had a magic wand,

- I'd make Web maximally interoperable, give an API to everything: look up Youtube recommendations or listen to Spotify programmatically or from the command line;

- introduce legislation to forbid non-interoperable for-profit (or infrastructure-level) software; otherwise businesses are incentivized to make walled gardens and lock-in users; e.g. no more countless chat apps;

- get rid of Javascript: it creates too many security and fingerprinting problems, and, if everything has an API, you don't need it;

- break up the browser into a composition of smallest independent components possible; it will get you `apt install facebook-local-events`;

- get rid of password-based authentication: what a horrible idea that was;

- get rid of any client-side possibility to track or fingerprint users; if you're making choices about what services to use or how, those choices can be fingerprinted, depending on some other things, but that's another matter; the other party should not be exposed to what hardware or software or configuration you use or how you use your peripherals;

- introduce consumer and competition protection laws to bring software out of the wild wild west in terms of legislation.

I've more or less described the destruction of Web as we know it, but also a creation of something much better, in my eyes. Doesn't sound very feasible, but that's what I'd do if I had a magic wand.

Re:Brython: an implementation of Python 3 running in the bro... by adminscoffee on Tuesday July 20, 2021 @05:37AM (#27891671)
has anyone attempted to create a separate standard yet?
Re:Brython: an implementation of Python 3 running in the bro... by dmos62 on Tuesday July 20, 2021 @06:58AM (#27892222)
There's loads of document distribution alternatives, both classical (like Gopher) and modern (like Gemini). I'm not familiar with them.
Re:Brython: an implementation of Python 3 running in the bro... by pjmlp on Tuesday July 20, 2021 @03:29AM (#27890936)
Except that is what is actually happening, despite what people like yourself wish, we are getting our Flash tooling back.

Blazor, Unity, Uno, Qt, TeaVM, the list is only getting bigger and it will only stop if WebAssembly is removed from the browsers.

Pandora box is open and the lid won't close.

Re:Brython: an implementation of Python 3 running in the bro... by johnmaguire on Tuesday July 20, 2021 @01:31AM (#27890391)
What would you change?
Re:Brython: an implementation of Python 3 running in the bro... by Tade0 on Monday July 19, 2021 @04:14PM (#27886803)
> not having for instance a SQLite natively

We had this for a brief moment in the form of Web SQL, but as a rule web standards require independent implementations to be developed, and all the implementors were using SQLite under the hood. The current alternative is IndexedDB - for better or worse.

> Is the browser environment becoming more dev-friendly with the adoption of WebAssembly?

Yes, but that doesn't have much to do with WebAssembly.

JavaScript as a language evolved, we have TypeScript with its flexible and expressive type system and bundling is becoming less of a pain with each consecutive framework re-written using ES2015 modules(and loaded via e.g. Snowpack https://www.snowpack.dev/).

WebAssembly is helpful when there's a need for some heavy lifting - e.g. in software codecs, but that's still a niche application.

Re:Brython: an implementation of Python 3 running in the bro... by peterthehacker on Monday July 19, 2021 @04:55PM (#27887155)
Technologies like TypeScript are still dependencies that require transpiling to vanilla JavaScript and add to the bundle size. While typescript is becoming more and more common (for good reason) it still is effectively a workaround that compensates for the unergonomic-ness of the browser environment. You could make the same argument for frameworks like Angular, React and Vue.

If WebAssembly replaced js, then newer, more efficient browser languages could be invented. Like a new implementation of typescript could be created that is statically compiled and more efficient. All of this transpiling from x to js and y to css would be unnecessary.

Re:Brython: an implementation of Python 3 running in the bro... by bri3d on Monday July 19, 2021 @05:24PM (#27887419)
The "y to CSS" part would still be there - even with WebAssembly, your UI options are still pretty much the DOM (great for documents and form entry, not so great for applications) or canvas (too low level and loses platform consistency, accessibility, usability, really every affordance of an operating system).
Re:Brython: an implementation of Python 3 running in the bro... by UnpossibleJim on Monday July 19, 2021 @10:51PM (#27889602)
I'm going to ask an ignorant question and I'm sorry, but couldn't you basically write an application in web assembly, using OpenGL and creating whatever UI you wanted in there, and just use CSS for the scaffold? You'd only need a mobile and desktop web app, but you'd need one anyway, right? (Note.. I'm very obviously not a web developer, so forgive my naivete).
Re:Brython: an implementation of Python 3 running in the bro... by bri3d on Tuesday July 20, 2021 @11:21AM (#27894856)
That was my second option - canvas.

WebGL is a type of HTML5 canvas context. Unfortunately, there are major drawbacks which I also outlined - it's too low level and loses platform consistency, accessibility, usability, and really every affordance of an operating system - you're starting over from scratch and loading in dependencies or writing your own implementation of some immensely challenging concepts (font rendering on its own is usually several hundred kb of code and could fill textbook upon textbook).

If you're familiar with GL UI frameworks like dear-imgui, they do all work pretty well in WebAssembly. But again, they're compromised from the start because you lose all OS consistency and accessibility. And unlike in games, where these frameworks are often employed, OS consistency isn't expected, and accessibility is sadly ignored, the experience of a cross-platform UI framework appearing in a canvas element on the web becomes jarring very quickly.

There is an alternative approach, like Google Docs employs and the sibling poster linked - combining the DOM for input elements with custom rendering. But, this is really, really complex and challenging.

Every time I develop applications for the web, I yearn for an application-focused presentation layer which provides the expected fundamentals around accessibility, OS consistency, and rendering layout while ditching the hacks-on-hypertext minefield of CSS and the DOM.

Re:Brython: an implementation of Python 3 running in the bro... by hnfong on Monday July 19, 2021 @11:21PM (#27889752)
Yes. For example: https://workspaceupdates.googleblog.com/2021/05/Google-Docs-...

But it's going to be a very "heavy" custom framework that takes time to download and load. Overkill in most cases.

Re:Brython: an implementation of Python 3 running in the bro... by UnpossibleJim on Tuesday July 20, 2021 @10:37AM (#27894277)
Ok. Makes sense. Thanks =)
Re:Brython: an implementation of Python 3 running in the bro... by peterthehacker on Monday July 19, 2021 @07:46PM (#27888575)
Good point. I was thinking of changing styles via DOM, like CSS-in-JS, but you’re right that “y to CSS” would still be there.
Re:Brython: an implementation of Python 3 running in the bro... by rpmisms on Monday July 19, 2021 @07:04PM (#27888293)
If TS is eventually added to the JS standard, I would be very happy. I've only picked it up in the past few weeks, but I'm consistently amazed at how much sense it makes
Re:Brython: an implementation of Python 3 running in the bro... by runarberg on Monday July 19, 2021 @11:49PM (#27889866)
You can actually annotate typescript types using JSDoc comments. So if you don’t like the added step of compiling your source down to JavaScript you can still write JavaScript with doc comments and then typecheck with `tsc --noEmit` which won’t run the compile step.

However I do see the appeal of the ergonomic of the TypeScript syntax. I hope TC39 will add something like optional type annotations to the spec.

Re:Brython: an implementation of Python 3 running in the bro... by rpmisms on Tuesday July 20, 2021 @03:12PM (#27897922)
It could be a feature flag, like `use strict`, but `use types` instead
Re:Brython: an implementation of Python 3 running in the bro... by runarberg on Tuesday July 20, 2021 @04:58PM (#27899238)
I’m actually hoping for something more akin to python’s optional type annotations. Where opting in is as simple as using type annotations. The runtimes (i.e browsers, nodejs, etc.) would then simply ignore them like they do with comments. But third party tools could use them to do some static analysis. Like mypy does for python (or tsc --noEmit does for javascript).
Re:Brython: an implementation of Python 3 running in the bro... by rpmisms on Tuesday July 20, 2021 @06:59PM (#27900354)
It really depends on if you want enforced typing, which is why I think a feature flag could be useful. There's room for both—explicit typing being available, and enforced types being a flag away.
Re:Brython: an implementation of Python 3 running in the bro... by julienb_sea on Monday July 19, 2021 @06:28PM (#27888018)
Transpiling is more about broad browser compatibility than anything else. In any event, even if you invented some more efficient browser language, it would likely need a universal browser-compatible compilation target anyway (like web assembly). This isn't particularly a step forwards from TS compilation to JS, and the loss of all common JS libraries would be a huge drag on adoption.
Re:Brython: an implementation of Python 3 running in the bro... by uryga on Monday July 19, 2021 @07:22PM (#27888409)
> TypeScript [...] adds to the bundle size.

tbh i haven't checked, but isn't the transpilation step for typescript just stripping out the type annotations? TSC is build-time only, so it won't factor into your bundle size, and i can't imagine the generated JS is significantly bigger than source -- if anything, it should be smaller ;p

Re:Brython: an implementation of Python 3 running in the bro... by actuallyalys on Monday July 19, 2021 @10:09PM (#27889418)
For comparison, ClojureScript, another language that compiles to JavaScript, adds to the bundle size, but in my experience, it's mostly because of the runtime (core functions and data types) because the Google Closure compiler optimizes the initial transpiled JS.

I would guess running the TypeScript output through the Google Closure compiler (or adding similar optimizations directly to the TypeScript compiler) could make TypeScript bundles comparable to JavaScript bundles or smaller. It looks like people see significant improvements running TypeScript output through Closure compared to just WebPack [0].

[0]: https://medium.com/appmonet/using-closure-compilers-advanced...

Re:Brython: an implementation of Python 3 running in the bro... by peterthehacker on Monday July 19, 2021 @07:42PM (#27888544)
It definitely adds to the bundle size, but how much it adds depends on your implementation. This discussion on the topic is pretty interesting [0]. One comment from that discussion says “it is possible to double to the size of your source code”.

[0] https://dev.to/haruanm/does-typescript-increase-the-bundle-s...

Re:Brython: an implementation of Python 3 running in the bro... by mr_toad on Tuesday July 20, 2021 @01:06AM (#27890263)
Not having direct access to the file system or the network or to a database are because of the sandbox, not because of JavaScript. You can do all those things in Node.

Web Assembly isn’t going to get rid of the sandbox.

Re:Brython: an implementation of Python 3 running in the bro... by gchamonlive on Tuesday July 20, 2021 @05:42AM (#27891711)
You could have fakeroot, for instance: https://wiki.debian.org/FakeRoot

Sandbox doesn't imply not having a file system available (for example, for use in imports), I believe this is more of a historic limitation than a strictly technical one (just because we need the sandboxing concept).

I know. Fakeroot is not strictly sandboxing, but I think it illustrates the point.

Re:Brython: an implementation of Python 3 running in the bro... by laurencerowe on Monday July 19, 2021 @01:57PM (#27885442)
That’s already pretty much the case. Python has been though it’s not fast and the stack size limit is problematic. https://github.com/pyodide/pyodide

Pyodide is used in https://jupyterlite.readthedocs.io/

Maybe things will improve with web assembly GC, though it will require work to port GC languages to it.

Re:Brython: an implementation of Python 3 running in the bro... by redfox2 on Monday July 19, 2021 @02:20PM (#27885701)
Guido mentioned he was focusing work on CPython to make Python faster
Re:Brython: an implementation of Python 3 running in the bro... by tiew9Vii on Tuesday July 20, 2021 @01:47AM (#27890466)
I don't think Webassembly will ever replace Javascript in the browser. Javascript has a low barrier of entry and if you are creating React/Angular sites there's little to gain from Webassembly for someone not interested in safer languages.

Saying that I am really interested in Webassembly and think the word web in Webassembly does it a disservice.

I have started to think of Webassembly as a light weight JVM. It's heavy sandboxing makes it really interesting as an evolution to FaaS (Function as a service) such as AWS Lambda. Lucet which Fastly is using for their Compute@Edge reports 35 micro second code start time! I can't wait until Fasly put there Compute@Edge on general release so I can try it. I've been playing with Cloudflare workers and as they us Chrome to run WASM files you have to mess about writing Javascript shims so a bit rough around the edges debugging.

Webassembly should realise the original goals of serverless providing a cross platform runtime with security guarantees and be fast and lightweight.

Most people package an entire OS in Docker containers, with WASM they get a small cross platform artifact. This project already looks like a way to run them in K8s https://github.com/deislabs/krustlet.

It also looks great for cross platform media devices. Have the bulk of your code as a WASM binary and then have very thin platform specific shim the WASM interacts with.

Re:Brython: an implementation of Python 3 running in the bro... by jacobmischka on Tuesday July 20, 2021 @03:19AM (#27890904)
I don't think this is ever going to happen. JavaScript is still and probably always will be the language used to manipulate webpages and interact with the user, it's extremely optimized and a quite fast and effective scripting language.

WebAssembly provides an amazing opportunity to do general computing in webpages more efficiently than with the JavaScript scripting language, but it's not designed to interact directly with the user or documents. Certainly that _could_ change in the future, but that's not one of its design goals and I don't think it would even be particularly effective at it.

Re:Brython: an implementation of Python 3 running in the bro... by divbzero on Tuesday July 20, 2021 @01:07AM (#27890267)
I’ve noticed both “plain HTML please” and “Wasm is awesome” sentiments expressed on HN. I wonder if these reflect two distinct subpopulations, or if there is an intersection of HNers who like both ideas.

The existence of both sentiments speaks to the idiosyncratic history of the web. The browser is powerful because it has grown to be ubiquitous, but also has this odd dual mandate of displaying static content and running dynamic apps.

Re:Brython: an implementation of Python 3 running in the bro... by diordiderot on Tuesday July 20, 2021 @02:47AM (#27890752)
I think it's more of a dislike for slow, laggy, and frankly janky experiences caused by excessive JavaScript or under qualified JS developers over the past 10 years.
Re:Brython: an implementation of Python 3 running in the bro... by rank0 on Tuesday July 20, 2021 @12:19AM (#27890026)
idk how I feel about web assembly. At least now we can see what client-side javascript is doing. If WASM becomes mainstream then all client side code is going to be essentially binary blobs.
Re:Brython: an implementation of Python 3 running in the bro... by ben-schaaf on Tuesday July 20, 2021 @02:07AM (#27890572)
With all the minification and JS being used as a compile target for other languages it's already essentially binary blobs.
Re:Brython: an implementation of Python 3 running in the bro... by rank0 on Tuesday July 20, 2021 @10:22AM (#27894071)
I agree with what you're saying but WASM is just way more difficult to reverse engineer. Also if WASM becomes the standard, everyone will have binary blobs running in their browser at every web page by default. At least now its only for web apps which are intentionally obfuscated/minified/transpiled/whatever...
Re:Brython: an implementation of Python 3 running in the bro... by NelsonMinar on Monday July 19, 2021 @08:49PM (#27888987)
It's about time to reinvent Java applets.