Hacker News new | past | comments | ask | show | jobs | submit login

I can't believe all the negative comments here. Someone has implemented Python in JavaScript. I personally think that is incredible.

> 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 ?

Not that I have anything against Brython (which imo is a cool project, although I'm not so sure if it's practical yet), but since you asked for it, here's an example where it does differ from python:

  x = 0
  def impure():
      global x
      x += 1
      return x

  print(0 < impure() <= 1)
In python, impure() would only be evaluated once returning True, but Brython's chaining evaluates it twice, and so it returns False instead. Of course, this example isn't exactly something you'd usually see in actual code (heck, it's probably even bad practice in most situations) BUT the point here is that while most of python might be compatible with this, there exists some inconsistencies that causes one's previously working python code to fail (and these bugs would probably be very difficult to trace). Of course, Brython is still young and has time to hopefully fix these issues. (In fact, this is the second time I've tried this project. Back then they didn't even have the chaining feature working, so it's nice that they are making progress.)

Nifty example, but this is why we have integration test suites.

PyPy, jython, ironpython etc all had/have incompatibilities as the language evolves and as they work out the quirks in their respective runtimes.

This isn't compatible with cpython (afaik, none of the other runtimes have ever been COMPLETELY compatible, but this is much further off), but hell, it's pretty awesome.

As an aside, I'd shoot anyone who did that ^^ without a pretty amazing explaination.

Well... if brython is running the CPython integration tests to aim for proper compatibility then fair enough.

It is a cool project, whichever one of these python in javasript things is to become successful needs to aim for the same level of compatibility as say Jython or IronPython - yes it would take a long time, but this sort of thing is needed to be a useful implementation.

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():  
      x = 2

I wonder if it's worth adding some failing tests to the project about these..

Things like this are why projects like pypy use CPython's test suite whereever the behavior is not CPython specific, and have contributed many tests back to CPython as well. These aren't minutia of the language, they are well understood and tested features that most moderately sized software projects are likely to rely on at some point.

That's not right, it is a translator/compiler. It simply translates a python code string into a JS code string, and then calls `eval()` on the JS code string. The `eval()` step can optionally be skipped so that you can precompile. This is much easier to implement than an interpreter anyway.

Yield support is buggy:

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

I think it's the hubris that's putting people off:

> Brython is designed to replace Javascript as the scripting language for the Web

If I wrote a Python implementation in JavaScript, I'd probably have some hubris about it as well.

I'm not sure if the developer is one person or if they wrote the landing page as well, but let's assume it is that same person.

If someone has focused enough energy to implement a language in JavaScript, it is probably fair say that marketing isn't his or her primary skill.

At the same time, reading over the text again, people have said crazier things and done much less. If the developer's goal is to replace JavaScript with Python and his or her first attempt is to implement Python in JavaScript, I, for one, applaud their effort.

That's a silly complaint. Doesn't every language designer feel that their product is better than the thing it desires to replace?

A better question: Is python really any better than JavaScript? Sure, it has advantages here and there. But there are things I like about JavaScript that are better than python. For example, having anonymous functions that are more than a single expression inside a lambda.

Yes, I know you can declare a function inside another and you get a closure. But, JavaScript's syntax is just nicer.

Wow. I had never seen that. There are literally tears streaming down my face I was laughing so hard.

I enjoyed it more this time than I did when I last saw it, perhaps because I was more familiar with the showcased peculiarities last time (the theme is garbage in, garbage out).

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.

JavaScript's syntax being 'nicer' seems pretty subjective.

"It will" would register as hubris, but "designed to" seems harmless to me.

In programmers, hubris is - along with laziness and impatience - a great virtue. In Larry Wall, they gave the world Perl.

I have a better idea for a new language based on python:

    and walked: "through the valley"' he's and feared: not: "evil"!
    # he.and_walked("through the valley").and_feared(not("evil"))!

    drop down:' criminal scum!
    # criminal_scum.drop_down()!

    eat: breakfast' you!
    # you.eat(breakfast)!

    kill: with pistol' maim: blunt object' opponent's check dead:
    # opponent.maim(blunt_object).kill(with_pistol).check_dead()

    print person's name's last
    print person's last' name # ;)
    # print person.name.last

    if my's cookies's jar's empty::
        print "Cookie Monster, why is the Cookie jar empty?"
        why: cookie jar's empty:' cookie monster 

        # why cookie monster, why? :)
        why: cookie jar's empty:' cookie monster's why: "?"

it's called Glas :)

Agreed! I'm all for constructive criticism, but some of the comments in this thread are unnecessarily negative. This project looks really cool!

I really do hope this (or something like it) takes off. More choice in languages is better, and JS has been the only option for too long.

It would be amazing if browsers added interpreters natively, then we could check for a native interpreter and fall back to loading a JS one like brython.

Applications are open for YC Winter 2023

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact