Live data from Hacker News

Brython - Python to Javascript translator

brython.info

31–40 of 71 posts

Re: Brython - Python to Javascript translator

#31
post #19

Python needs to be natively supported as a scripting lang in browsers. Google, MS, Firefox - make it so!

As much as I like Python, I don't think this is the right approach. What browsers need to do is to have a machine-level bytecode, so that they can download whatever interpreters are needed to run the scripting code the page uses. Then pages can be written in whatever language the developer feels is best. This is the real potential of something like Native Client - although it doesn't look like that potential will be…

Pages downloading and executing things just reminds me of ActiveX from the late 90s. I think South Korea still relies on the technology for their home-grown version of SSL.

Re: Brython - Python to Javascript translator

#32

Wow! This is so awesome. This has been tried before, but I don't remember why it never succeeded. I wonder if this can get the appropriate community to make it a decent alternative compared with TypeScript and CoffeeScript - or maybe I'm missing something here?

Once brython gets some key missing Python features (classes, list comprehensions, lambdas), and some libraries for it, I think it has huge potential.

Re: Brython - Python to Javascript translator

#33
post #2

I think compiler is the wrong way to describe this. A computer program that translates between two different high level languages is typically called a language translator .

Wouldn't "preprocessor" be a more accurate description?

No. A preprocessor usually translates into the same or a very similar language.

Re: Brython - Python to Javascript translator

#34

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.

Much of the slowness was because emscripten was immature at the time that repl.it worked on their port. If someone built python with current-day emscripten it should be much faster.

There is a better way, though. We could compile PyPy's generated C implementation and add a JIT to JS to that. That would be the best way to get fast python into the browser. If anyone is interested to hack on that let me know, I would assist from the emscripten side.

Note though that this would only give throughput speed, not startup speed. For startup speed, a method like pyjamas or bython will do better - at the cost of not fully supporting the python language, of course.

Re: Brython - Python to Javascript translator

#35
post #29

Earlier quoted context omitted.

As much as I like Python, I don't think this is the right approach. What browsers need to do is to have a machine-level bytecode, so that they can download whatever interpreters are needed to run the scripting code the page uses. Then pages can be written in whatever language the developer feels is best. This is the real potential of something like Native Client - although it doesn't look like that potential will be…

As much as I don't like Microsoft, I actually think the .NET CLR would be an excellent choice for such a runtime. NaCl not so much; target architecture-dependent compiled code is a major downside.

There's PNaCl: http://www.chromium.org/nativeclient/pnacl/building-and-test...

Re: Brython - Python to Javascript translator

#36
post #29

Earlier quoted context omitted.

As much as I like Python, I don't think this is the right approach. What browsers need to do is to have a machine-level bytecode, so that they can download whatever interpreters are needed to run the scripting code the page uses. Then pages can be written in whatever language the developer feels is best. This is the real potential of something like Native Client - although it doesn't look like that potential will be…

As much as I don't like Microsoft, I actually think the .NET CLR would be an excellent choice for such a runtime. NaCl not so much; target architecture-dependent compiled code is a major downside.

What about pnacl?

http://www.chromium.org/nativeclient/pnacl/building-and-test...

Re: Brython - Python to Javascript translator

#37

Wow! This is so awesome. This has been tried before, but I don't remember why it never succeeded. I wonder if this can get the appropriate community to make it a decent alternative compared with TypeScript and CoffeeScript - or maybe I'm missing something here?

We made a similar compiler with the same goal of supporting text/python but it only compiled python it down into javascript. We could manipulate images from the webcam and make calls to jQuery and through python.

In the end, it was hard to replicate 100% of the usefulness of JS through python and convert python's cool features into JS.

Re: Brython - Python to Javascript translator

#38

Wow! This is so awesome. This has been tried before, but I don't remember why it never succeeded. I wonder if this can get the appropriate community to make it a decent alternative compared with TypeScript and CoffeeScript - or maybe I'm missing something here?

> This has been tried before, but I don't remember why it never succeeded.

Because as cool as the project is (from a scientific perspective), ultimately it will end up not being used by anyone. Most developers and companies who build production grade software for a living stick to true and tried technologies, vs. fancy esoteric stuff like this.

Don't get me wrong, I am not knocking this project and the person who created it, I am just stating the obvious reason why things like this rarely take off.

Re: Brython - Python to Javascript translator

#39
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 ghastly Python.

The difficulty is providing all the class semantics and the standard library.

Re: Brython - Python to Javascript translator

#40

Very nice. Can this approach be generalized to embed Clojure, Haskell, and other languages into the browser? I love the pervasiveness of JavaScript but I dislike writing it. This is a very good tradeoff.

There are already implementations of Clojure and Haskell that target JavaScript, but I'm not sure if that's what you meant. I don't know if there are any implementations that target JS using this specific approach but I don't think it's one to necessarily emulate; as nostrademons points out it is interesting, but not really optimal.

https://github.com/clojure/clojurescript

http://www.haskell.org/haskellwiki/The_JavaScript_Problem

https://github.com/jashkenas/coffee-script/wiki/List-of-lang...

Post reply on HN