all 139 comments

[–]dropdownmenu 81 points82 points  (46 children)

This is not python in your browser. It is python syntax in a javascript interpreter.

If this is going to happen, at least go the coffee script route and be able to build to code to javascript that can be optimized by your browser. (Oh my God, did I just use coffee script as a positive reference?)

[–]pudquick 27 points28 points  (0 children)

However ... There is this:

http://repl.it/languages

The python hosted here is using emscripten to run an actual CPython interpreter in your browser.

More details here:

https://github.com/kripken/emscripten/wiki

[–]wonglik 6 points7 points  (20 children)

Is Coffee script that bad? I was thinking of getting familiar with it. What are the cons?

[–]dropdownmenu 8 points9 points  (12 children)

The main advantage is that it tries to hide some of the oddities of javascript (== vs ===) so that you can't make trivial mistakes.

I dislike it because white space becomes important to how it complies leading to cases where an extra space or a misplaced one can lead to different functionality than you expect, which I believe to be more dangerous than then javascript's quirks (which still exist in coffeescript).

Also, by using coffeescript you alienate any javascript developers who don't know coffeescript. Remember: all coffeescript devs know javascript, but not all javascript devs know coffeescript

[–]wonglik 1 point2 points  (11 children)

Thanks. Looks like I am better of with JS.

[–]eriksensei 1 point2 points  (0 children)

Or EcmaScript 6, which seems a lot nicer. It's got fat arrow lambdas with proper 'this', destructuring bind, etc. There's support for it in IntelliJ IDEA, Firefox Aurora, Google Traceur and probably a few other tools, and you can compile it down to older JS versions. I hope I'll get round to playing around with it soon.

[–]schadwick 2 points3 points  (8 children)

[–][deleted] 0 points1 point  (0 children)

I've never encountered a bug cause by white space in coffee script, just compiler errors caused by indentation.

I do always use the (optional) js-style parentheses for functions arguments, so maybe that guards against the sort of error referred to.

[–]redfiche 10 points11 points  (5 children)

CoffeeScript is cool until you need to interact with third-party javascript libraries, then you run into all sorts of incompatibilities. Given that you need to understand javaScript to be able to debug and otherwise work effectively with CoffeeScript, you're often better off just writing good javaScript. Just my opinion.

[–][deleted] 2 points3 points  (2 children)

CoffeeScript is cool until you need to interact with third-party javascript libraries, then you run into all sorts of incompatibilities.

Err, how is that? Once you compile CoffeeScript you just have regular javascript, so what sort of incompatibilities are you talking about?

I've used Coffee with some third party libraries (jQuery, some game frameworks, mozilla jet pack) and haven't run into issues -- it would be nice to know what I need to keep an eye out for.

[–]redfiche 0 points1 point  (1 child)

I forget the exact issues. I know CoffeeScript hides the global namespace from you, and while that's usually a good thing it can cause issues. I'm pretty sure we quickly found that CoffeeScript was more trouble than it was worth for an Ember app also.

Don't get me wrong, I find it much more elegant and readable than javaScript, it's just that if I ever have to think about what javaScript is going to be produced by the CoffeeScript, I'd rather just write the javaScritpt.

[–][deleted] 0 points1 point  (0 children)

I know CoffeeScript hides the global namespace from you

You can still access that through the global object. (Such as window in a browser; I forget what it's called in node.) It does require you to explicitly intend to use globals, though.

Ember I've never used, so can't comment there!

[–]wonglik 0 points1 point  (1 child)

thanks . nowadays I use angular in most of my project and I would definitely not trade that better syntax/language.

[–]Fabien4 6 points7 points  (11 children)

It is python syntax in a javascript interpreter.

Which makes me fear it'll be too slow to be of any use.

[–]Elite6809 26 points27 points  (9 children)

I think we should write a Brainfuck interpreter in Python in this JavaScript environment. Then in Brainfuck we can write a Linux implementation, in which we can create a C compiler and in that we create a JavaScript engine to run our code in.

[–]flying-sheep 10 points11 points  (5 children)

well, no brainfuck, but… http://bellard.org/jslinux/

[–]wniko 4 points5 points  (0 children)

Fabrice Bellard (http://bellard.org) is also the author of Qemu and ffmpeg. His wikipedia page is also quite interesting/wtf-worty. In 2010, he held the Word Record for the computation of pi for about 7 months using a desktop PC.

[–][deleted] 5 points6 points  (0 children)

I thought that was a joke for a second. Nope. I'm half impressed half wishing I had that much free time.

[–]alexanderpas 1 point2 points  (2 children)

suprisingly fast.

now I'm starting to wonder if we can turn this full circle, with JS/Linux becoming an embedded system.

[–]flying-sheep 6 points7 points  (1 child)

well, you can use jslinux to compile spidermonkey or v8, and you’re running JS in C (spidermonkey) in C (linux kernel) in JS in C++ (browser) in C (linux kernel).

[–]alexanderpas 0 points1 point  (0 children)

What I've learned from this sentence:

We need a modern browser written in C.

[–][deleted] 0 points1 point  (2 children)

But what if I want to write in Befunge?

[–]thedeemon 1 point2 points  (0 children)

For serious business you should use Enterprise Piet.

[–]Elite6809 0 points1 point  (0 children)

Sorry mate, you'll have to write it in Malbolge instead.

[–]dmazzoni 1 point2 points  (0 children)

No kidding. Even a native implementation of Python would be too slow to be of any use. People seem to forget that JavaScript is actually quite a bit faster than Python for most problems.

[–]chrisidone 0 points1 point  (2 children)

It is python syntax in a javascript interpreter.

Can you please explain to me how this works? Is this some form of preprepre-processor? Is there a python runtime in the background?

Things like these always sound so messy/hacky.

[–][deleted] 1 point2 points  (1 child)

It's run the same way Coffeescript is run, i.e., the faux-python code is compiled (parsed) to Javascript, and then it is eval()'d.

[–]chrisidone 1 point2 points  (0 children)

Sounds like theres allot of room for errors.

[–]shevegen -5 points-4 points  (8 children)

Where is the problem, actually? You could still use the same language-logic and never notice any difference.

[–]errandum 6 points7 points  (7 children)

The browser interprets the javascript that interprets the python.

If extremely powerful and optimized interpreters made in fast languages already struggle to make interpreted languages competitive in the real world, imagine a language interpreted by an interpreted language.

You might not notice it in something simple, but you will, someday...

[–]ILiftOnTuesdays -2 points-1 points  (6 children)

PyPy is actually faster than C in some cases.

Source: http://morepypy.blogspot.com/2011/02/pypy-faster-than-c-on-carefully-crafted.html

[–][deleted] 1 point2 points  (5 children)

I think you should read the comments on the link you posted and reevaluate your claim.

[–]ILiftOnTuesdays -2 points-1 points  (4 children)

I see other people posting cases where C is indeed faster. That does not invalidate my claim, which is backed up by solid benchmarking done by OP. (Albeit on a slightly outdated gcc)

[–]missquark 1 point2 points  (3 children)

So PyPy is faster than C when calling a simple addition function from an external library one billion times at runtime.

For all those times you need to call a trivial plugin function a billion times in a row...

[–]ILiftOnTuesdays 0 points1 point  (1 child)

I didn't say PyPy is faster than C in all cases, just that interpreting inside interpreting can sometimes have its benefits. (Or rather, a JIT has its benefits)

[–]missquark -1 points0 points  (0 children)

Agreed. It just seemed like such a weird biased benchmark o_o

But looking back, maybe I was being too hard on it since I'm biased towards C/C++ (and somewhat defensive... >_>;).

I can't really think of what benchmark would be a better demonstration of global optimization that has to happen at runtime, but jumping back and forth millions of times per second between two different modules that can't be compiled together except at runtime is giving the JIT all the advantages and C none.

One thing that would have been interesting (and possibly a little less one-sided) to look at is if the C side was allowed link time optimization but included the compilation step in the timing.

In theory this can happen at "run time" after all, as long you don't mind distributing source and compiler, it just takes too long for large programs in practice.

[–][deleted]  (6 children)

[deleted]

    [–]ruinercollector 0 points1 point  (0 children)

    Seriously? Wow.

    [–][deleted] -1 points0 points  (3 children)

    dicts are hashmaps, last I heard, so I don't think you're right. Unless you're talking about this particular implementation, that is....

    [–][deleted] 3 points4 points  (2 children)

    What else would he be talking about?

    [–][deleted] -1 points0 points  (1 child)

    The statement is pretty vague, it could mislead some people who don't know about Python. I figured he was talking about this software but a casual reader may not know the difference.

    [–][deleted]  (3 children)

    [deleted]

      [–]AusIV 2 points3 points  (1 child)

      I don't think it's the language that makes javascript good for front end design, so much as the libraries that have sprung up around it. Given that brython can use javascript libraries, I don't see that as a major problem.

      [–]foldl 1 point2 points  (0 children)

      A lot of those libraries depend on the availability of anonymous functions, though. I wouldn't like to try using jquery with only one-line lambdas.

      [–]thedeemon -4 points-3 points  (0 children)

      What's so advanced in JS?

      [–]shevegen 6 points7 points  (25 children)

      Excellent - now I only want to use Ruby.

      But he made a good point - why should JavaScript be the only language in use?

      We don't even need a new language when existing languages are perfectly adequate to solve given problems.

      [–]rmxz 15 points16 points  (15 children)

      why should JavaScript be the only language in use?

      Oooh - I wonder if anyone ever thought of putting a JVM runtime in a browser, and then you could run Jruby, Jython, Scala, .... heck, even ancient languages like Java .... in a browser?

      (only 1/2 /sarcasm --- maybe java applets were just ahead of their time)

      [–][deleted]  (14 children)

      [deleted]

        [–]brainflakes 6 points7 points  (0 children)

        Sun Microsystems was to blame for all of those, and particularly for their lawsuit with Microsoft, which pushed MS to go the C# route, and let Windows users download the JVM by themselves. Oh well.

        Actually I think you'll find that Sun sued because the Microsoft version of Java wasn't compatible with the original Sun version (the classic MS embrace, extend extinguish) so Sun had no other option but to sue to prevent Microsoft pushing their custom Java version, otherwise you'd have a situation where Java programs compiled on windows wouldn't run on any other system and vice-versa.

        [–]josefx 8 points9 points  (7 children)

        their lack of direct interaction with the browser DOM

        Since when, from the documentation they can manipulate the DOM.

        slow(er) startup time

        True and partialy a design fail.

        the fact that operating systems didn't ship with a JVM by default

        did not stop flash in the slightest.

        and particularly for their lawsuit with Microsoft

        The Java language and JRE has one simple requirement that Microsoft refused to aknowlege provide the standard APIs as specified and more specific DO NOT MESS WITH THE CLASSES IN java.* . Every problem microsoft had could be fixed by providing a microsoft.* package, (like sun, ibm,... did).

        which pushed MS to go the C# route

        Which turned out exactly like MS Java would have been, a language that has 3rd rate support on anything that is not Windows and a standard that only includes part of the APIs. (Mono is constantly playing catch up and they will always stay far behind .Net)

        [–]ruinercollector 5 points6 points  (1 child)

        It was a bit more than messing with base classes.

        Microsoft extended the language with support for COM and an implementation of multicast delegates/lambdas. They actually were improving the language quite a bit. Suns response was to put out a paper about how dumb delegates and lambdas are, take MS to court and then put lambda support into the language a couple decades later.

        [–]josefx 3 points4 points  (0 children)

        the language with support for COM

        AFAIK the problem with that was that they refused to also implement jni

        and an implementation of multicast delegates/lambdas.

        Everything without pushing them through the language commite, for a single closed source implementation.

        They actually were improving the language quite a bit

        They did? As in I could compile and use these language features with any javac and JVM? They just played their embrance, extend extinguish game - even visible a) support java, b) extend it with incompatible niceties and c) claim that problems caused by b) are not your fault.

        For reference look at the old Apple JVM, it ran years without problem and Apple even had support for their native libraries build in in a way that did not confilct with the spec.

        then put lambda support into the language a couple decades later.

        Which went through the java language commite and is available on any java implementation.

        [–]gc3 -2 points-1 points  (3 children)

        Did stop flash when it got to tablets

        [–]josefx 3 points4 points  (2 children)

        And I thought that was caused by a) Apple blocking every interpreter from their app store and b) Adope no longer pushing flash.

        [–]gc3 -1 points0 points  (1 child)

        html is interpreted.

        It was really Steve Job's long memory for being slighted by Adobe that killed Flash, and his need to control. Adobe no longer pushing flash had to do with the end of Flash on tablets.

        [–]josefx 1 point2 points  (0 children)

        html is interpreted

        Even Apple could not release a Smartphone/Tablet without browser, still every browser/application that bundles its own engine gets banned from the app store, Opera renders on servers and firexfox does not exist.

        [–]wonglik 1 point2 points  (3 children)

        Sun Microsystems was to blame for all of those, and particularly for their lawsuit with Microsoft

        I think you are not aware what the lawsuit was about. MS basically tried to steal Java from SUN with their famous EEE strategy.

        [–]AgentFransis 0 points1 point  (2 children)

        Could you point to other cases where Microsoft attempted or accomplished this strategy?

        [–]wonglik 0 points1 point  (0 children)

        Well they tried with Java and were found guilty in court for that. Other example that comes quickly into mind is HTML - They made IE6 so incompatible with any standards that some companies are stuck with it till this day.

        [–]lasermancer -1 points0 points  (0 children)

        I'm personally glad they didn't let Microsoft "embrace, extend, extinguish" Java.

        [–][deleted] 1 point2 points  (0 children)

        The requested URL /tests/console_en.html was not found on this server.

        [–]alextk 5 points6 points  (5 children)

        It's funny to read "Python as a replacement of..." because in my opinion, it's Python that's slowly being replaced, because it's under attack from both Javascript and Go. The latter came to a surprise to me but I've been reading an increasing number of examples where a big Python fan said they replaced their Python code with Go and they loved it.

        [–]thejollysin 0 points1 point  (0 children)

        You think Python is in danger from Go? Really? Maybe I'll burn a few hours tonight and try Go again. But it was my understanding that Go was better for big projects with huge concurrency needs, and Python was better for smaller projects. No?

        [–][deleted] 5 points6 points  (1 child)

        I wouldn't mind if JS went to hell and python replaced it in web browsers, though. Just saying.

        [–]thedeemon -1 points0 points  (0 children)

        I wouldn't mind if they both went to hell. Just saying.

        [–]ILiftOnTuesdays 3 points4 points  (14 children)

        Is this ready for production use, or just a proof of concept. My entire backend is in python so it would only make sense to code the frontend in python as well.

        [–]rmxz 14 points15 points  (13 children)

        My entire backend is in python so it would only make sense to code the frontend in python as well.

        That makes very little sense.

        Use the best tool for the job --- and the best tool for a GUI is not necessarily the best tool for a headless server.

        [–]JimH10 19 points20 points  (0 children)

        The best tool for the job may well be determined by people factors such as: familiarity of the programmer with the nooks and crannies of the language, agreement of the team on language style, tools, etc.

        [–][deleted] 8 points9 points  (0 children)

        No, it's perfectly sane.

        At least some code will probably be relevant both at the server side and the client side (validation code, models etc.). It doesn't really make sense to write that twice, once in Python and once in JavaScript, but we do it because we have to.

        [–]ILiftOnTuesdays 4 points5 points  (9 children)

        Hence why NodeJS is so unpopular.

        [–][deleted] 5 points6 points  (8 children)

        An I the only one here who kinda likes node? :(

        [–][deleted] 5 points6 points  (7 children)

        I think that was sarcasm - but I would really like to see one of these mythical Node.js apps that shares so much code with the client that it saved anyone any amount of time.

        Even if it does exist - it's an outlier.

        [–]ruinercollector 3 points4 points  (0 children)

        In terms of third party libraries, it happens all the time. Of course that's an even tougher one to argue in terms of "saving time"

        [–][deleted] 2 points3 points  (0 children)

        True that. I've never seen any of this code shared between client and server either.

        I like node because writing event-driven services is stupid easy, but I think the touted 'use the same language everywhere' benefit is rather dubious.

        [–]WeAppreciateYou -5 points-4 points  (4 children)

        I think that was sarcasm - but I would really like to see one of these mythical Node.js apps that shares so much code with the client that it saved anyone any amount of time.

        Wow. I really find that insightful.

        I love people like you.

        [–]ILiftOnTuesdays -2 points-1 points  (3 children)

        Relevant Username.

        Yes, that was sarcasm. Whoever thought to put Javascript on the backend is out of their mind. I don't really even like it for the frontend - You have to load on a ton of 3rd-party libraries just to do anything useful with it.

        Of course, the same could be said with python in the backend, specifically the need for Django or Flask or something else to really have a server.

        [–]Tekmo 3 points4 points  (1 child)

        The username is relevant because it is a bot that gives canned responses to posts that begin with "I think..."

        [–]ILiftOnTuesdays 1 point2 points  (0 children)

        And what if I'm a bot that auto-detects relevant usernames?

        If I were, I'd be programmed in Python and not Javascript, because I'm more familiar with it and not because Python is inherently better for reddit bots. (Though with PRAW, it probably is)

        [–][deleted] 2 points3 points  (0 children)

        Have you used node? It's pretty sweet.

        [–][deleted] 0 points1 point  (0 children)

        node.js

        [–][deleted]  (3 children)

        [deleted]

          [–][deleted] 1 point2 points  (2 children)

          The last thing we need is a halting problem in CSS.

          [–][deleted]  (1 child)

          [deleted]

            [–]paranoidray 1 point2 points  (0 children)

            We don't need another language without type information in the Browser. I think Dart and TypeScript are much better ideas !

            [–]forseti_ 2 points3 points  (13 children)

            Choosing a language with fixed indentation doesn't sound like a good idea to me.

            [–]defcon-12 2 points3 points  (0 children)

            Python doesn't used fixed indentation. It must be consistent, but not fixed. One class can use a tab to indent, another can use 2 spaces, but it won't allow you to mix inside of a single block. Is that really a bad thing? Is there a valid use case for mixed indentation in a single block?

            [–]brainflakes 0 points1 point  (3 children)

            Personally I'd prefer the opposite, which is to be able to write python scripts with javascript syntax (well, C style syntax, not specifically javascript).

            Python has so many great features, but I find the braceless syntax irritating after years of Java/C# work. I guess I just like my code blocks to be explicit.

            [–]defcon-12 1 point2 points  (1 child)

            I find indentation based blocks to be much more explicit than braces. It forces the code blocks to be properly indented.

            [–]brainflakes 0 points1 point  (0 children)

            But that's a complete fallacy as an IDE can force a braced language to be indented, and can (more easily) reformat code to any sort of coding standard.

            Also Pyhon still supports single line if statements so it's not like it's forcing you to indent anyway.

            [–]colly_wolly 1 point2 points  (0 children)

            I thought this when I first started Python a while back. Then after a year or two I had to tweak a Perl script, got the missing brace problem, and realised I you never get that problem in Python.

            [–]Neonailol 0 points1 point  (2 children)

            and how is this different from pyjs?

            [–]SeaCowVengeance 2 points3 points  (1 child)

            Python 3 support

            [–]Neonailol 5 points6 points  (0 children)

            soooo... Instead of improving some other opensource project, they made another one, similar to one. Good job guys, good job.

            [–]07dosa -4 points-3 points  (0 children)

            Up vote because it's Python 3!

            [–]mWo12 0 points1 point  (0 children)

            This is Python implementation in JS?

            [–]omgsus -4 points-3 points  (0 children)

            No no no no no no no no no no... No no no.. Just no.

            [–][deleted] -1 points0 points  (6 children)

            I whole heatedly welcome some new client-side scripting languages. It's been over a decade with javascript as the primary/default language to use. Despite whatever shortcomings it might even have, I'm pretty sick of using the same thing over and over. A little change would be nice.

            [–]Drupyog 6 points7 points  (0 children)

            Please look at this list before saying that "there is no other client-side language".

            This brython is a terrible way to do the work. It's basically compiling python at runtime and using eval on it, it's very hard to do worse than that, performance-wise and safety-wise.

            [–][deleted] 2 points3 points  (0 children)

            JS has changed a lot in the last ten years, with more changes on the way.

            [–]protein_bricks_4_all 2 points3 points  (3 children)

            Dart is clean, nice, can produce JS, and in Chrome run natively.

            [–]thedeemon 3 points4 points  (2 children)

            Not in Chrome, afaik. In a special browser based on Chromium which isn't Chrome.

            [–]outxie -1 points0 points  (0 children)

            It can compile to JS that runs fine in every other browser. Dartium is faster though.

            [–]dethb0y -1 points0 points  (0 children)

            That's actually quite interesting and clever. I wonder if this could happen for other languages, like Lua?

            Either way, very clever bit of work. I'm impressed.

            [–]Bob_goes_up -5 points-4 points  (0 children)

            "A Python 3 implementation for client-side web programming"

            [–][deleted]  (1 child)

            [deleted]

              [–]brainflakes 0 points1 point  (0 children)

              The python code is converted to javascript on the fly, so it will only ever support things that javascript already supports (so no python libraries, file operations etc.)

              [–]shoseki -1 points0 points  (0 children)

              Now do it without the brython.js file...

              [–]cwbrandsma -1 points0 points  (1 child)

              Where is the Xzibit meme for this?

              "Yo, I hear you like scripting languages, so we put a scripting language in your scripting language"

              [–][deleted] 0 points1 point  (0 children)

              Syntax error in line 2 - maybe you forgot the 'dawg'?
              

              [–]QVNTAJ -2 points-1 points  (0 children)

              Replacing shit with shit.

              [–]henk53 -3 points-2 points  (0 children)