Live data from Hacker News

Brython - Python to Javascript translator

brython.info

21–30 of 71 posts

Re: Brython - Python to Javascript translator

#24
post #10

Good luck with compiling anything without having AST trees and proper parser infrastructure. In it's current state this thing won't fly.

They seem to have taken an interesting approach - it's a Javascript source file that translates the source for a restricted version of Python into equivalent Javascript constructs and then interprets that. A JS-based interpreter for Python-like text, basically. I don't think I would've implemented it this way, because: 1. It introduces the latency of having to download brython.js with every page load. 2. It supports…

> I doubt he got the class & metaclass semantics right.

Brython doesn't implement classes at all, so you're right!

Re: Brython - Python to Javascript translator

#25
post #10

Good luck with compiling anything without having AST trees and proper parser infrastructure. In it's current state this thing won't fly.

They seem to have taken an interesting approach - it's a Javascript source file that translates the source for a restricted version of Python into equivalent Javascript constructs and then interprets that. A JS-based interpreter for Python-like text, basically. I don't think I would've implemented it this way, because: 1. It introduces the latency of having to download brython.js with every page load. 2. It supports…

The big advantage of Brython is that it has a very fast workflow, much like JavaScript. A server-side compiler approach would have a slower interactive workflow.

Re: Brython - Python to Javascript translator

#26
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 achieved any time soon.

Re: Brython - Python to Javascript translator

#28

Earlier quoted context omitted.

They seem to have taken an interesting approach - it's a Javascript source file that translates the source for a restricted version of Python into equivalent Javascript constructs and then interprets that. A JS-based interpreter for Python-like text, basically. I don't think I would've implemented it this way, because: 1. It introduces the latency of having to download brython.js with every page load. 2. It supports…

The big advantage of Brython is that it has a very fast workflow, much like JavaScript. A server-side compiler approach would have a slower interactive workflow.

That's true, but you could probably get it to load & reparse the files off disk every request and serve the JS dynamically. If you've ever used Django or AppEngine, you just edit your templates and source files, you don't have to do a manual compile & load style every time you change things. There's no reason you couldn't set your PyJS serving URL to do the same.

In terms of absolute CPU cycles burned, it's actually faster that way, since parsing happens in C using Python's built-in facilities, and the amount of JS shipped to the browser is less.

Re: Brython - Python to Javascript translator

#29
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…

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.

Re: Brython - Python to Javascript translator

#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.

Post reply on HN