Transcrypt – Python in the Browser
transcrypt.org
transcrypt.org
Debatable. But either way it's definitely a much worse language than Typescript so I agree.
It's only about avoiding the ambiguity of js, it js in general.
I remember making a small webapp in flask and ajax. Most of the code is on the server, it's as little js as possible, and it has no js dependencies.
https://www.python.org/dev/peps/pep-0020/
I especially likes this one:
> There should be one-- and preferably only one --obvious way to do it.
It's true that the standard library is good, but generally I do more things with basic python than the base of other languages.
And honestly I've never understood how js prototypes work.
Python just feels better. The syntax is less cluttered. That's a huge point of python.
- sequence[start:finish:step]
- no need for "==="
- try/except with specific exceptions
- context managers
- yield from
- "in" on any iterable
- raise from
- every empty object is false, all other are true
- spread work on all iterables, not just arrays
- f"{2:03}", f"{2:.2f}" and f"{date:%m/%d/%Y}"
- / and //
- no need for variable declaration keywords
- 0b1111
- "else" in loops
- := makes for explicit assignation + comparison instead of a footgun
- None instead of null + undefined
- set literals
- matmul operator
- foo > bar > baz
- sorting callback semantics
- dunder methods for operator overriding
- list, dict and set comprehension
- generator expressions
- byte literals
- raise SystemExit() for clean script exit
- raw strings
- automatic string literal concatenation
- positional/keyword only parameters
- can use *args and **kwargs together, as opposed to spread
- docstrings
- typing is part of the language, no need for a transpiled dialect like typescript
- "async for" and "async with"
That's only what I come up on the fly, I'm pretty sure I can double the list. Then of course, do we consider builtin to be part of the stdlib, since it doesn't require any import? Because there is a load to say there.
JS does have some nice stuff too though:
- ? and ??
- futures are more ergonomic than coroutines and awaitable anyway
- more powerful destructuration
- regex literals
https://docs.python.org/3/library/weakref.html#weakref.final...
comprehension alone are a game changer - language wise
I use pyodide at the moment in datastation [0] to provide an in-browser-memory demo environment. It means that environment is completely free other than static hosting costs while you get a nice (demo) computational notebook in your browser.
And while brython only implements a subset of Python and breaks some things like dict access for JavaScript interop, pyodide and coldbrew are complete cpython environments just running on wasm through emscripten.
The biggest issue with these binaries on wasm is that they take forever to load each time you come to the app. It takes like 20-30s to load. That's a pretty bad experience for my use case.
So I'm still testing every implementation I see out to find the right combo of fast load time and most pythonic implementation.
This all sounds pedantic but it's because not all "python in browser" implementations work like this.
Of course that means your site would be inaccessible to anyone with a normal browser so you couldn't run it in production... but were you really ever going to run something like this in a production environment anyways?
https://brython.info/static_tutorial/en/index.html
> In the <head> zone we load the script brython.js : it is the Brython engine, the program that will find and execute the Python scripts included in the page.
It looks like Brython works by embedding a Python interpreter into the page as Javascript. That's 5 MB if you include the standard library - almost 800 KB for just the interpreter. Not to mention the computational overhead of running an interpreter in an interpreter.
I think Grail could do what you were talking about, but it never got any traction. I also vaguely remember there being a python plugin floating around back in the day, kind of like flash, but I can't find any reference to it.
> Grail lets you download Python programs that execute inside Grail on your local machine. These little applications ("applets") can do things like display animations, interact with the user in new ways, even create additional menus that pop up dialogs if you like.
It’s lightweight, in accordance Pareto’s rule adapted for IT: 99% of the result can be achieved with 1% of the effort.
It offers the semantic essence of Python along with the clean syntax that the language is famous for
It cooperates flawlessly with the JavaScript universe of web-oriented libraries
It translates Python into highly readable, easy to debug JavaScriptIt was certainly not something I knew about before.
Got the demo to work. Seems neat. But I'm so far on the back-end these days all I can do is nod my head politely.
JSON is a win, though.
Ah, but you've hit against ones of Python's biggest limitations compared to JavaScript (the two languages being semantically very similar): poor support for functional programming paradigms. And that is in no small part due to limited lambda/closure support (no multiline lambdas).
You can also use arrow functions to avoid the function in modern JavaScript.
"Functional Python Programming: Discover the power of functional programming, generator functions, lazy evaluation, the built-in itertools library, and monads, 2nd Edition" was a great read =>https://www.amazon.com/Functional-Python-Programming-program...