Live data from Hacker News

A Python 3 implementation for client-side web programming

brython.info

91–100 of 120 posts

Re: A Python 3 implementation for client-side web programming

#91
post #90

Earlier quoted context omitted.

In all my Python years, I have never needed to write a long anonymous function. I consider it a bit of a code smell. This isn't to say it's wrong to do in JS, just that the patterns in Python are different so you don't use this in practice.

I have never needed to write a long anonymous function. So two line of code is long now?

Yes, as opposed to "short", i.e. a lambda. I'm sorry if my terminology offends you.

Re: A Python 3 implementation for client-side web programming

#92
It's a really nice demo, and I really like the idea so far (although precompiling to JS would be awesome), but I really don't see Python taking over Javascript as the scripting language.

It's way nicer in my opinion, but I think its fussy white space is likely to be an issue for this use case. All the large Javascript libraries get minified etc, and Python really isn't open to that sort of stuff. It's a great language to use normally, but I don't see it replacing Javascript. I'd much rather write in Python and compile to Javascript though.

Re: A Python 3 implementation for client-side web programming

#93

Earlier quoted context omitted.

> Someone has implemented Python in JavaScript. This isn't really true. This is far from a Python implementation. At best you could call it a Python-esque syntax to Javascript translator. And that's perhaps still useful. But to call this a Python implementation is quite simply a lie.

This is not a translator but an interpreter, there is no compilation. edit: except FUD, can you provide some points on which brython is failling, please ?

There's no support for metaclasses. type is missing entirely. nonlocal doesn't work. docstrings and some other double underscore names are just missing (__class__, __name__, etc.). Unicode literals don't work. dis obviously won't work since there isn't a bytecode compilation step. Scoping, like in the following code, behaves improperly:

  x = 1  
  def test():  
      print(x)  
      x = 2

Re: A Python 3 implementation for client-side web programming

#94
post #14

I do like the idea, but it inevitably suffers from the same flaw that afflicts all other compile-to-js libraries: making sense of errors will still require knowledge of how the underlying javascript works. Perhaps a development plugin for Chrome would allow debugging in python?

Every exception in brython has original line source, you don't need source maps. The thing is that you can't type Python in the console, yet.

Just a matter of implementing a Chrome extension to extend the developer tools with the compiler.

Re: A Python 3 implementation for client-side web programming

#95

Earlier quoted context omitted.

> Someone has implemented Python in JavaScript. This isn't really true. This is far from a Python implementation. At best you could call it a Python-esque syntax to Javascript translator. And that's perhaps still useful. But to call this a Python implementation is quite simply a lie.

This is not a translator but an interpreter, there is no compilation. edit: except FUD, can you provide some points on which brython is failling, please ?

Yield support is buggy:

    def f():
        n = 0
        while n 
This prints 0, 1, ... 10, 0 instead of just 0

Re: A Python 3 implementation for client-side web programming

#96
post #83

The way they position Brython is pretty off-putting and kind of confuses the issue. CoffeeScript page: "CoffeeScript is a little language that compiles into JavaScript." Brython page: "Brython is designed to replace Javascript as the scripting language for the Web." Maybe that's the end goal, but the reality is far from it. Of course JS is still required, and of course the Python gets compiled into JS. Finally, the a…

The approach and the phrasing seems exactly right to me and not at all off-putting. The goal of Brython is to replace javascript on the web, seems straightforward right? The way they go about it is to implement a compiler in javascript, and use that to bootstrap a python in the browser community. Seems like that is much easier than convincing Chrome/Firefox/IE to include a python compiler in their browser. How would…

Why not provide both options, ala LESS?

Re: A Python 3 implementation for client-side web programming

#97
post #26

Earlier quoted context omitted.

Noscript allows you to turn the Javascript off. Requiring javascript to see any content at all is a little absurd.

Javascript is a prerequisite of the modern web. Refusing to accept that is absurd.

First of all, he was commenting about this page not displaying ANY content at all. At the very least there should be a noscript tag to tell the user to enable JS.

Second, I whitelist sites for javascript. There's nothing absurd about that. Honestly, I can't believe people run any and all JS on every random page they land on.

Re: A Python 3 implementation for client-side web programming

#98
post #66
post #9

Link to console demo from that page is broken, sadly. edit: looks like if you remove "_en" then you get to the right place, http://www.brython.info/tests/console.html Looks like pyjs, in that it has python syntax but JavaScript semantics, for example numbers turn into doubles here (but should be arbitrary-precision ints in Python).

Well, python 2.7: >>> a = 1/3 >>> type(a) int python 3.2 >>> a = 1/3 >>> type(a) brython: print(type(1/3))

Correct, that's a python 2/3 difference. But both 2 and 2 have arbitrary precision integers AFAIK, try this code

    x = 1
    for i in range(100):
        x = x*2
        print(i, x)

Re: A Python 3 implementation for client-side web programming

#99

I love this. I wish someone would do this for Ruby. Not CoffeeScript - I want to be able to write Ruby that manipulates DOM objects.

Here's eight options for you. Enjoy: https://github.com/jashkenas/coffee-script/wiki/List-of-lang...

Last time i checked it, it contained links to old/dead projects, which seems still the case. Anyway AFAIK there is no such a similar thing to Brython for ruby, and by that I mean a ruby implementation specifically written in JS and optimized to deal with DOM and browser environment in general (if anybody knows about something like that or is working on it please inform me). It'd be such a great thing to have!

Re: A Python 3 implementation for client-side web programming

#100
post #98
post #66

Earlier quoted context omitted.

Well, python 2.7: >>> a = 1/3 >>> type(a) int python 3.2 >>> a = 1/3 >>> type(a) brython: print(type(1/3))

Correct, that's a python 2/3 difference. But both 2 and 2 have arbitrary precision integers AFAIK, try this code x = 1 for i in range(100): x = x*2 print(i, x)

Indeed. Just to verify that it's not just a difference in (string)representation, something like:

    print(9**32-(9**32-5))
Also works (brython returns 0, python2&3 return 5)
Post reply on HN