Live data from Hacker News

Brython - Python to Javascript translator

brython.info

61–70 of 71 posts

Re: Brython - Python to Javascript translator

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

> has wrong complexity

Python doesn't specify the complexity of dicts, that they're "efficient" is a CPython implementation detail other runtimes happen to copy. Even a worse-than-linear time mapping that satisfies the protocol is still a 'dict'. Surprised you don't know this given your relationship to PyPy.

As for whether I'd prefer a 100kb "not quite Python" or sending a few MB of JS (that takes 10 minutes to translate for each change) to the browser just to handle a few functions in a cross-platform manner, I'm glad to see more options when making this choice.

I'm in the midst of evaluating a solution to running simple mathematical functions on a Python backend or in-browser (for graphing). In a case like this, a handful of crappy guarantees about the lowest common denominator arithmetic is all I need in a solution. It's easy to get wrapped up in correctness, but ease and practicality trumps it almost every time.

Re: Brython - Python to Javascript translator

#62

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…

There's no such thing as a language-agnostic bytecode. A bytecode is just a compressed source encoding of some language.

I take it you never heard of the JVM, or Microsoft's CLR.

Re: Brython - Python to Javascript translator

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

> has wrong complexity Python doesn't specify the complexity of dicts, that they're "efficient" is a CPython implementation detail other runtimes happen to copy. Even a worse-than-linear time mapping that satisfies the protocol is still a 'dict'. Surprised you don't know this given your relationship to PyPy. As for whether I'd prefer a 100kb "not quite Python" or sending a few MB of JS (that takes 10 minutes to trans…

indeed, python does not specify the complexity, it's just what everyone expects.

Anyway, my problem is not with "not quite Python", my problem is with calling it "Python". As long as you call it "a language with Python inspired syntax", it's seriously left to the reader whether he likes it or not. If you call it Python, it's fine to have something incomplete, however provide a way forward at least. This seems to be incredibly far from supporting full Python, which might or might not be a goal.

Re: Brython - Python to Javascript translator

#64
post #43

Earlier quoted context omitted.

Python is a really big and complicated language to include in Browsers. And think of the version hell: If you think Pyhthon 3 compatibility is apain, imagine if we still had to use Python 2.2 on Firefox or something like that.

These arguments are terribly heuristic. The full stack of software included in any significant JavaScript app is big and complicated. There are already runtime differences, and we aren't saying that those make JS unusable. There is not going to be a big 3->4 migration any time remotely soon. No 'version hell'. The current story for Python compatibility is certainly much worse!

> The full stack of software included in any significant JavaScript app is big and complicated.

But those are libraries under your control at least. The "problem" with Python is that the language itself is big. Normally this is a non-issue, since you can upgrade your interpreter version when your code stack supports it but on the web you don't get that luxury because you are forced to use whatever interpreter the users have.

Re: Brython - Python to Javascript translator

#65
OK, how about :

1) getting Python ==> LLVM bytecode

2) then using emscripten (https://github.com/kripken/emscripten/wiki) to run LLVM in browser?

An option to perform the first step seems to be : http://code.google.com/p/py2llvm/

Or 'simply' getting CPython ported on emscripten?

Any opinions on this suggestion?

Re: Brython - Python to Javascript translator

#66

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_JavaS…

These are all neat, but they require some effort to bootstrap. The neat thing about Brython is that you can start writing Python immediately. I’ve played with ClojureScript and it takes a while to get the QuickStart to work.

I think Brython is cool, not from an efficiency or machine-performance point of view, but from a human point of view. It makes it easy to start hacking. The barrier to entry is non-existent.

Re: Brython - Python to Javascript translator

#67
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’d rather have a partial and easy-to-use implementation of Python in the browser that exists right now than a perfect implementation that doesn’t exist.

Re: Brython - Python to Javascript translator

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

Please get over yourself.

Re: Brython - Python to Javascript translator

#69
post #65

OK, how about : 1) getting Python ==> LLVM bytecode 2) then using emscripten ( https://github.com/kripken/emscripten/wiki ) to run LLVM in browser? An option to perform the first step seems to be : http://code.google.com/p/py2llvm/ Or 'simply' getting CPython ported on emscripten? Any opinions on this suggestion?

I've seen that done already, but the resulting Python interpreter has no visibility of the DOM or access to the browser. You have basically a Python console, which is quite useless if what you want is to substitute Javascript.

Re: Brython - Python to Javascript translator

#70
post #69
post #65

OK, how about : 1) getting Python ==> LLVM bytecode 2) then using emscripten ( https://github.com/kripken/emscripten/wiki ) to run LLVM in browser? An option to perform the first step seems to be : http://code.google.com/p/py2llvm/ Or 'simply' getting CPython ported on emscripten? Any opinions on this suggestion?

I've seen that done already, but the resulting Python interpreter has no visibility of the DOM or access to the browser. You have basically a Python console, which is quite useless if what you want is to substitute Javascript.

Just for reference, there's an example of CPython compiled to JavaScript using Emscripten running in the browser at http://syntensity.com/static/python.html
Post reply on HN