8 ms·
Transcrypt – Python in the Browser
- eesmith 5y agoIt's come up before on HN (https://hn.algolia.com/?dateRange=all&page=0&prefix=false&query=Transcrypt&sort=byDate&type=story https://hn.algolia.com/?dateRange=all&page=0&prefix=false&qu... ) but not much in the way of comments. It 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.
- smitty1e 5y agoSomehow seeing the function keyword to the right of the '=' in Javascript bothers me, and I'd rather not do JS if possible. JSON is a win, though.
- nicoburns 5y ago> Somehow seeing the function keyword to the right of the '=' in Javascript bothers me, and I'd rather not do JS if possible. 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.
- smitty1e 5y agoKinda need to have you elaborate on 'poor' here. "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-programming-built/dp/1788627067/ref=mp_s_a_1_3 https://www.amazon.com/Functional-Python-Programming-program...
- hencoappel 5y agoTranscrypt is a tool to compile a fairly extensive subset of Python into compact, readable JavaScript. It has the following characteristics: 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 JavaScript
- eatonphil 5y agoUnlike brython, pyodide or coldbrew you'll need a server to run the transcrypt program to get JavaScript from your Python. 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. [0] https://github.com/multiprocessio/datastation https://github.com/multiprocessio/datastation
- guipsp 5y agoYou don't need a server, you just need to transpile beforehand.
- eatonphil 5y agoSure I meant that when used in prod you'd probably compile your Python to JavaScript on a (CI) server and/or if you wanted to dynamically run Python in the browser using Transcrypt you'd have to send the code to a server to be translated before you could run the resulting code in the browser. This all sounds pedantic but it's because not all "python in browser" implementations work like this.
- CivBase 5y agoOne approach I've still never seen is native browser support for Python - something like what Google's Dart team did with Dartium. 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?
- 5y ago
- wilsonfiifi 5y agoPlayed around with Transcrypt a bit. Works quite well with Mithril.js [0]. Would be great if it could work seamlessly with esbuild but I couldn’t find any existing plugins. [0] https://mithril.js.org/ https://mithril.js.org/
- JasonFruit 5y agoThis is one where I don't see the advantages outweighing the disadvantages. Python is, IMO, a moderately better language than JavaScript, but you don't get the Python ecosystem, and you aren't running the same code you wrote, so you won't get nice stack traces or even useful error messages. You'll be writing JavaScript in Python, using JavaScript libraries, but all the references are written in JavaScript. It's a lot of mess just to avoid writing JavaScript, which contains a pretty decent language at this point.
- chrisseaton 5y agoIf you have some business logic that you want to run on both the front-end (maybe for quick local validation) and the back-end (for definitive validation) then this is useful over possibly rewriting you Python into JavaScript.
- IshKebab 5y ago> Python is, IMO, a moderately better language than JavaScript Debatable. But either way it's definitely a much worse language than Typescript so I agree.
- jokoon 5y agoThe base syntax of python is already a big plus when compared to js. 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.
- peanut_worm 5y agoWhat do you think is better about Python’s syntax? I generally like modern JavaScript’s syntax. I always figured the appealing part about python is the very good standard library.
- jokoon 5y agoList comprehension, the indent syntax that makes it very readable, the builtin functions, globally everything. The philosophy of python is well described here: https://www.python.org/dev/peps/pep-0020/ 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.