5 ms·
I've never understood the point of special browser only languages. Why don't browsers support a sand-boxed python (or insert favorite language x) with some sor
by Yxven 15y ago
I've never understood the point of special browser only languages.
Why don't browsers support a sand-boxed python (or insert favorite language x) with some sort of standard dependency management? It already has JIT compilation, is cross-platform, bytecode, a wealth of libraries, etc. Why are we reinventing this wheel?
- MostAwesomeDude 15y agoFirefox nightlies do support Python. It's unfortunate that nobody wants to migrate away from JS though.
- tikhonj 15y agoWhy is it unfortunate? Once you learn it properly, JavaScript is a very pleasant language to work in and, I find, quite a bit more expressive than Python. It also doesn't make using a functional programming style painful the way Python does.
- romaniv 15y agoAre you implying that anyone who doesn't consider JavaScript a "very pleasant language" must simply not know it "properly"? Are you implying that there are no other possible reasons?
- MostAwesomeDude 15y agoWhat does "functional programming style" mean? Does it mean lambdas or other anonymous functions? Python lets you close over names at any scope and define functions anywhere; you don't need the "lambda" keyword. Even if you want to only use lambdas, it's been shown that Python does not need statements, only expressions, to express everything, although you quickly turn your code into Scheme-soup. JS doesn't somehow improve on this. Is it first-class functions? Python has those, just like JavaScript, although Python goes further, enabling you to have real bound methods, descriptors, properties, class methods, and all other kinds of fun. Is it map, filter, and fold? Python's still got map, filter, and fold (foldl, called "reduce" in Python.) Python also has list comprehensions, borrowed from Haskell, as well as generator expressions, providing that valuable laziness that some functional languages value so much. And, in Python 3, there are set and dictionary comprehensions as well. JavaScript doesn't have comprehensions at all. Is it referential transparency or immutability? Unlike JavaScript, Python refuses to allow you to edit the values of certain builtin types, like str and unicode. So, uh, what did you mean, exactly?
- effn 15y agoThe lack of tail call optimization, persistent data structures, pattern matching and the cumbersome lambda syntax makes functional programming style very painful in Javascript.
- ootachi 15y agoPython is much harder to make fast due to its highly dynamic nature. (Yes, Python is a much more dynamic language than JS -- see del(), locals(), code objects, etc.)
- MostAwesomeDude 15y agoThe work has already been done; see PyPy (http://pypy.org/ http://pypy.org/).
- beagle3 15y agoI'm not sure how locals() or code objects makes Python much more dynamic than JS -- even on it's own, but especially since it very rarely appears in idiomatic python code. Nothing in Python comes close to the dynamic mess that is JavaScript's "with" (bindings in Python are lexical; "with" makes bindings in JavaScript dynamic!) Even if you were right, you could still make code that doesn't use these features fast, and slow back to interpreted if any of these features is used -- that's what JS JITs do when they see "with". And finally, Lua is as dynamic as Python (both of which are, in my opinion, less dynamic than JS thanks to lexical binding). And Lua has been made significantly faster than any Python or JS implementation (Mike Pall's LuaJIT2)
- tikhonj 15y agoJavaScript isn't a special "browser-only" language. It's just a normal interpreted, dynamically typed language (much like Python or Ruby) that just happens to run in all browsers. Right now it also happens to be quite a bit faster than Python or Ruby (as far as I know) and is also extremely expressive and flexible. The fact that Python has "a wealth of libraries" isn't particularly pertinent--web apps mostly need web-specific libraries, which Python doesn't have (because it isn't in the browser). Most people using JavaScript get by with jQuery, maybe some web ui framework and perhaps something like Raphael. And, with the advent of node and server-side JavaScript, JavaScript is getting more and more libraries outside of the browser as well. Of course, the browsers could support a bunch of different languages, but I think the complexity outweighs the (limited) benefits. Google, obviously, disagrees and thinks that Dart should also be an option, but I really think it isn't worth the effort. Ultimately, JavaScript is more than good enough as a browser language; while it does have some annoying quirks, upcoming versions (and things like "use strict") are getting rid of most of them. There really is no overwhelming reason to switch away from JavaScript, and even just adding another language is probably not worth it.
- Yxven 15y agoJavascript was originally built for the browser and later expanded to other areas. I'm not claiming that python wouldn't need a new standard library to manipulate a browser's dom tree or whatever. That's about all it would need though, so it seems like it would have been far less work to embrace and extend than to completely start over. You seem to be arguing from the perspective (and please correct me if I'm wrong) that javascript is a good solution and a fine programming language, and I am not claiming otherwise. I just don't understand why so much effort has been spent creating and polishing Javascript instead of making slight improvements to a previously established quality language. I suspect the answer is that your browser has an advantage if your javascript engine is faster, but there can be no advantage if everyone uses the standard python interpreter.
- tikhonj 15y agoI'm not sure why Netscape decided to write their own language for the job. Perhaps integrating a different language into their browser would have been difficult back then. Now, however, JavaScript is a well-established language so there is no need to replace it with anything else. Also, unless I'm unaware of something, wasn't Perl the most popular scripting language back then? So if they had included an already existing language, Perl would probably have been the best bet.
- azakai 15y ago> Why don't browsers support a sand-boxed python (or insert favorite language x) with some sort of standard dependency management? It already has JIT compilation, is cross-platform, bytecode, a wealth of libraries, etc. Why are we reinventing this wheel? 1. Python is not sandboxed. Security is necessary in a web browser. 2. Python has some JIT work, mainly PyPy, but even so is much slower than JavaScript. 3. You can compile Python into JavaScript (see demo at repl.it), where it will be sandboxed. Similar reasons apply to other proposed languages, for a web language we need security, speed, standardization, and portability (and often we can already compile them into JS, so the motivation is lessened anyhow). I am unaware of any option that has all of those to the extent that JavaScript does.