I have a Node background so I might be biased but... Why would you want python in the browser?
Like, I get the appeal of more languages beyond JavaScript for the frontend, but I'd have guessed this would mostly be attractive to people who like significantly different languages to js, like maybe something compiled and strongly typed.
Python and Javascript seem to be in the same ballpark of "interpreted scripty language grown larger". I don't think moving to python would give me a different enough language to warrant the cost of switching.
I have mentioned it on HN before, but I strongly believe that bringing Python to the browser, especially via WASM, and going as far as bringing on a templating library, would allow Python to match things like C#'s Blazor, which honestly has been a productivity boost on web projects.
I'm totally all-in on WASM over JavaScript, unless your back-end is also JS/TS then no objection.
I could see Django benefitting greatly from being able to run template logic in-browser.
WASM is fine for original applications, like desktop applications, because a WASM application is everything plus the kitchen sink.
WASM is a bad idea for web applications as a JavaScript replacement because it’s everything plus the kitchen sink. Most of time people advocating for this are people that cannot program JavaScript. Don’t feel bad about that though, because most people writing JavaScript cannot program JavaScript.
This wouldn't make sense. JavaScript offers all the utilities necessary, and operates with all web elements.
Converting python code to WASM would cause even less performance than JavaScript.
The only reason to do something like this is if you only know Python and refuse to use anything else.
The web is the only platform where people routinely chide other people for wanting to use their favorite programming languages. For some reason not liking Javascript and wanting to use something else is offensive to a lot of people. In all the other platforms some language may dominate but others are still used and don't cause these reactions.
> The web is the only platform where people routinely chide other people for wanting to use their favorite programming languages.
Oh, I've been plenty chided for wanting to use Node on the server, and not something faster like Go. Although you may have included web backend into 'the web'.
on other platforms, all languages are relatively equal, it's the same effort to use language a as it is to use language b, and you can get nice results with both
vs on the web, javascript is built in, and you have to specifically go out of your way to use something else (which be a worse experience than the one that's already built in*)
*idk, i don't have personal experience, but i think that's the reasoning at least
> The only reason to do something like this is if you only know Python and refuse to use anything else.
The ignorance and prejudice of most developers are staggering. They simply think "Javascript is shit", and all their arguments boil down to jokes about NaN and the weird behavior of ==. JS is (by far) not a jewel of a PL but it's telling that those people don't know anything about the real cursed and weird parts of JS (such as: eval does not behave the same depending on how you call it...).
You can dismiss their objections as childish, but people are gonna write in the language they want to (or are paid to) write in. If there's a large body of existing python code they'd have to rewrite in JavaScript, or use some python in the browser route for their purposes, why should we force other people to use typescript because some of us think it's better?
of course, LLMs, with their nascent ability to translate code into different languages, makes the question of rewriting something in a different language more tractable, but it's still a hike.
I mean, these things aren’t static. Python may be the second most popular language (behind JS/TS) today, but what if elixir takes over 10 years from now? There is no need for browsers to implement every language-of-the-day.
Additionally, browser JS adheres to a quite strict backwards compatibility requirements. Python can and does deprecate and remove APIs, and I would imagine the community would not like to lose that flexibility.
WASM is probably the best bet here, in that it provides a well-specified low-level target, such that the door is open for other languages for anyone who is allergic to learning/using javascript.
How does WASM make less sense than the current paradigm of treating JS as "byte code for the browser"?
Python is not that different from Typescript. Neither can be interpreted by the browser. Both can be compiled into JS or WASM to be run in the browser.
You could, theoretically, render django templates in the browser today. But you'll still need to contend with using a thin JS layer to access the browser dom. Mooting any real performance benefit, at least if you want accessibility and not a 00s-style flashblob of a page. AFAIK direct dom bindings for wasm aren't being taken seriously and may never really happen.
I’m also super excited about wasm creating language democracy. I’m rooting for dart myself.
Never used dart until about a month ago for Flutter. Really loving it so far - like a better typescript. So many cool language features.
In your opinion, why is Dart a better TypeScript? Interested to hear your view, because my experience was quite different. When I learned Dart, I was mostly annoyed because it was almost exactly the same as TypeScript, but just different enough that I had to look up how to do everything again. Like, I understand that Rust is different from other languages because it brings in a totally new approach to software development, which has its use cases. But when I used Dart, I just wondered why Flutter didn't just use TypeScript, since it looks basically the same to me.
As someone that mainly codes in Python and only has rudimentary JS skills, I'm intrigued. The generative art pyscript demos mentioned in the blog post are really nice.
Using decorator calls to "compile" chunks of python code seems like an increasingly popular trend in ML (and presumably other numerically intensive code) - e.g., numba, jax.jit and triton.
very interesting. So all the declarative stuff, like various type descriptions and preconditions and such, can be precompiled.. (and i am not talking about type-hints/annotations). Maybe some of the meta-programming stuff too.
i was thinking some weeks ago that it may be time to "fork" python - as language - in a way to preserve the initial simplicity and clarity it did have and is losing faster and faster. But, nevermind. Will have to live with whatever there is.
edit: looking at the code, some things might be optimized but no idea if these are on critical path (like, that switch-by sq_idx, or 6 lines.append.. ), or whether func-calls are as expensive in Spy as they are in Cpy. But anyway, squeezing few percents is not the point.. if one needs magnitudes.
(SPy author here) function calls in SPy are as cheap as in C.
You can check by yourself seeing of the spy compiler translates the code to C in the (super-experimental) spy playground: https://antocuni.pyscriptapps.com/spy-playground/latest/
>i was thinking some weeks ago that it may be time to "fork" python - as language - in a way to preserve the initial simplicity and clarity it did have and is losing faster and faster.
I've had this thought, and seen others express it. The main problem is there is no general agreement on what should or shouldn't make the cut.
I've sort-of designed a new language from scratch, but I haven't been able to convince myself to make time to implement anything significant, or even really discuss what I've already figured out in any detail.
I do like Mr. Langa's idea about pre-computed ("@blue") code - although it doesn't strike me as particularly novel. (It's something I want to do in my own language, too - or rather, I have in mind a metaprogramming system, so you'd have macros that manipulate the AST and either insert a result when it's fully determined at compile time, or runtime code otherwise.)
Actually i don't have that much of a problem with the language itself - the new additions are not mandatory nor breaking old stuff, by design. But the way some are used - and started to be applied and forced-down-throat regardless of usecase - leaves me wanting those features to be absent. Better not have gold at all than turn everything into gold - it's not edible.. (here mostly talking about the type-hinting frenzy. But, no point repeating myself)
The actual code example he made runs about 100 times faster in Spy/emscripten than in Pyodide.
[stub for offtopicness]
[flagged]
[flagged]