Live data from Hacker News

Brython - Python to Javascript translator

brython.info

11–20 of 71 posts

Re: Brython - Python to Javascript translator

#11
This looks really nice! It seems like the other side of the Python-in-the-browser coin to Empythoned (https://github.com/replit/empythoned) used by repl.it (http://repl.it/).

(Ignore this...)The mime-type is wrong though, there isn't an authoritative mime-type for Python, so it should use a private subtype like text/x-python or application/x-python.

Re: Brython - Python to Javascript translator

#12
post #8
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 .

Not anymore, see Closure Compiler, CoffeeScript compiler, TypeScript compiler, dart2js compiler, and tons more: https://github.com/jashkenas/coffee-script/wiki/List-of-lang... It's pretty common now to call these "compilers".

Yeah, a compiler is anything that translates from one programming language to another. The definition of a "high level language" is muddy these days - is C a high-level language? It's a compiler target for Scheme, Haskell, Goo, Python, and many other programming languages these days. It's also a source language for gcc, Clang, and numerous other C compilers.

Re: Brython - Python to Javascript translator

#13
post #11

This looks really nice! It seems like the other side of the Python-in-the-browser coin to Empythoned ( https://github.com/replit/empythoned ) used by repl.it ( http://repl.it/ ). (Ignore this...)The mime-type is wrong though, there isn't an authoritative mime-type for Python, so it should use a private subtype like text/x-python or application/x-python.

RFC 6648: Deprecating the "X-" Prefix and Similar Constructs in Application Protocols

"""Historically, designers and implementers of application protocols have often distinguished between standardized and unstandardized parameters by prefixing the names of unstandardized parameters with the string "X-" or similar constructs. In practice, that convention causes more problems than it solves. Therefore, this document deprecates the convention for newly defined parameters with textual (as opposed to numerical) names in application protocols.

This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community."""

Re: Brython - Python to Javascript translator

#14
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 only a subset of Python, whatever the implementor has gotten around to implementing. That's a pretty small subset so far - no list comprehensions, and I doubt he got the class & metaclass semantics right.

3. It'll run slowly because all the Python code is running through an interpreter, through a language that itself isn't blazingly fast.

I would've done this as an on-the-server compiler from Python to JS, using Python's built-in ast module to parse the source directly, translate to an intermediate representation, and output optimized Javascript. That seems to be the approach PyJS takes, which seems to be a much more mature and well-designed project.

Re: Brython - Python to Javascript translator

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

The technical term is "transpiler". However, people tend to use "compiler" interchangeably without much confusion.

Re: Brython - Python to Javascript translator

#16
post #13
post #11

This looks really nice! It seems like the other side of the Python-in-the-browser coin to Empythoned ( https://github.com/replit/empythoned ) used by repl.it ( http://repl.it/ ). (Ignore this...)The mime-type is wrong though, there isn't an authoritative mime-type for Python, so it should use a private subtype like text/x-python or application/x-python.

RFC 6648: Deprecating the "X-" Prefix and Similar Constructs in Application Protocols """Historically, designers and implementers of application protocols have often distinguished between standardized and unstandardized parameters by prefixing the names of unstandardized parameters with the string "X-" or similar constructs. In practice, that convention causes more problems than it solves. Therefore, this document de…

Oh, neat. Thanks for the pointer!

Re: Brython - Python to Javascript translator

#18
This is long overdue - The DOM is a great model of objects, but javascript is not the way forward. For all the admittedly great work that has been done to improve it, it's still a mess of a language.

Native support of Python would be my dream (I don't see why there's not 3-4 competing languages in the browser; though the complexity of such is a decent argument against), but this solution seems to be a great stopgap, as well as compatible with future in-browser python implementations.

Post reply on HN