Live data from Hacker News

Brython - Python to Javascript translator

brython.info

51–60 of 71 posts

Re: Brython - Python to Javascript translator

#51

Once upon a time I wrote Oink, which generates JS from Python on the server: https://github.com/alecthomas/oink It has support for many of the Python niceties: classes, list comprehensions, positional arguments, and so on. Interesting experiment, but I ended up thinking that Python is not the best language for the browser.

Because its syntax can't work with the DOM, or what?

Re: Brython - Python to Javascript translator

#52
post #30

Looks really cool. And i love Python. However, I think the Python Syntax will make it hard to minify the code, which is probably not that important anyway when not in production. But for production usage it would be cool to have a real compiler instead of an interpreter. But yeah. Cool stuff.

I guess you could just gzip your python code without minification, here's a little bench: https://github.com/jch/gzip_vs_minify

Re: Brython - Python to Javascript translator

#53
I'm genuinely shocked that this made it to the top of hackernews. I would expect better. While the idea of having the Python interpreter in the browser is very likely better than having a compiler Python -> JS (if we care about Python), the implementation here is both half assed and really bad. It takes quite a bit of effort to create a python interpreter that can be called python. This is nowhere near there. On top of it double-interpretation in dynamic languages is very slow and I doubt someone is willing to pay that price here. A good example of low quality is here:

http://code.google.com/p/brython/source/browse/trunk/py_clas...

this is both incorrect (exceptions are propagated, http://paste.pound-python.org/show/28457/) and has wrong complexity. It's not even a dict at all!

Re: Brython - Python to Javascript translator

#54
post #53

I'm genuinely shocked that this made it to the top of hackernews. I would expect better. While the idea of having the Python interpreter in the browser is very likely better than having a compiler Python -> JS (if we care about Python), the implementation here is both half assed and really bad. It takes quite a bit of effort to create a python interpreter that can be called python. This is nowhere near there. On top…

I will be more shocked if I discovered that people dive this deep into code before upvoting, because it is generally not the case. If you think of it, we would have missed your valuable input if people didnt upvote this for you to see. :)

Re: Brython - Python to Javascript translator

#55

Repl.it has supported python on the browser for a while: http://repl.it/ (an an interpreter, not as a translator, though). It also supports ruby, scheme, lua and others[1] What made it impractical was the slowness. Emscripten seems to work fine for clang[2], not so much for interpreted languages. Maybe the translator path can solve this issue. [1] http://repl.it/#:languages [2] https://developer.mozilla.org/en-US/dem…

> What made it impractical was the slowness.

Although, speed is way less important when the code is running on lots of browsers out there, compared with running lots of instances on your server.

Re: Brython - Python to Javascript translator

#56
post #53

I'm genuinely shocked that this made it to the top of hackernews. I would expect better. While the idea of having the Python interpreter in the browser is very likely better than having a compiler Python -> JS (if we care about Python), the implementation here is both half assed and really bad. It takes quite a bit of effort to create a python interpreter that can be called python. This is nowhere near there. On top…

It is an indication that we just want to get a python for the web really bad.

If someone makes a good looking website for his project it kind of gives the impression that he is seriously going for it, perhaps it is not good now, but maybe it will become a serious contender later.

Re: Brython - Python to Javascript translator

#57
post #53

I'm genuinely shocked that this made it to the top of hackernews. I would expect better. While the idea of having the Python interpreter in the browser is very likely better than having a compiler Python -> JS (if we care about Python), the implementation here is both half assed and really bad. It takes quite a bit of effort to create a python interpreter that can be called python. This is nowhere near there. On top…

All people are different...

There are many OPs that assert that JS syntax/lang are beautiful once you get handle of it, and may be it is...

However, there may be enough people like myself for whom the JS syntax/lang just do not fit into the brain. Since at my last job of CFO of $200+m pharma country org I have architected multidimensional db for an OLAP cube for SAP Business Objects, I do not think that I am that dumb. But this JS stuff just does not fit in.

Also, I do value my time. So although I could persist in learning JS, as a general rule when things do not flow - the learning time multiplies. I do not have time.

Hence, personally I would love to be able to write/maintain code in Python [even subset of Python would be fine], knowing that it cleanly compiles to JS. It will be then my choice whether I want it client-side or server-side [smth like what css pre-processors SASS/Less are doing].

Re: Brython - Python to Javascript translator

#59

If you want to do this kind of thing on the server side, Python provides enough introspection to turn functions in a live Python image into JavaScript. Here's a minimal example I tossed together a while back: https://gist.github.com/50d706081074aed8fcf6 I have a bunch of notes somewhere on translating a big hunk of the basic language, including how to generate continuation passing style code in JavaScript from less g…

I like the simplicity of that gist. Very cool hack.

However if I was to implement a Python to JavaScript compiler, would there be some benefits in transforming the Python AST into a JS AST first?

There are existing code generators such as escodegen that transform that AST to JavaScript code.

Post reply on HN