[HN Gopher] A possible future of Python in the browser
___________________________________________________________________
A possible future of Python in the browser
Author : milliams
Score : 64 points
Date : 2025-02-25 09:15 UTC (13 hours ago)
(HTM) web link (lukasz.langa.pl)
(TXT) w3m dump (lukasz.langa.pl)
| giancarlostoro wrote:
| 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.
| MattDaEskimo wrote:
| 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.
| athanagor2 wrote:
| > 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...).
| fragmede wrote:
| 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.
| pphysch wrote:
| 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.
| pedrocr wrote:
| 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.
| dang wrote:
| [stub for offtopicness]
| tewmakr wrote:
| [flagged]
| 2OEH8eoCRo0 wrote:
| [flagged]
| svilen_dobrev wrote:
| 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.
| hoodchatham wrote:
| The actual code example he made runs about 100 times faster in
| Spy/emscripten than in Pyodide.
| antocuni wrote:
| (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/
| zahlman wrote:
| >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.)
| svilen_dobrev wrote:
| 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)
| ripped_britches wrote:
| I'm also super excited about wasm creating language democracy.
| I'm rooting for dart myself.
| hyperbolablabla wrote:
| Never used dart until about a month ago for Flutter. Really
| loving it so far - like a better typescript. So many cool
| language features.
| firejake308 wrote:
| 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.
| dimatura wrote:
| 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.
___________________________________________________________________
(page generated 2025-02-25 23:00 UTC)