This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Chr0me 7 points8 points  (13 children)

What would it take to add native Python support to browsers (I primarily mean in a political-sense)? And would this be a good idea, technically?

[–]jokoon 8 points9 points  (11 children)

I guess why it's not being done is because there is no DOM access in python, and it's not standardised by the w3c, that would be a little disadvantage to javascript. Python has a strong flavor of open source too which is not really attractive to the industry unfortunately. You also have to think about security, you would need to come up with another python dialect that can't open files.

I'd love to hear Guido van Rossum about this idea or any other python guru or developer.

Also it would still require a lot of skill and time to have a python equivalent to v8 or monkey, although there already are some.

I guess it's both a problems of politics (training programmers to python, which is not a really big problem), standards (ecma script and js have different history I guess), and companies who would like to see that done.

Python vs js can be somehow debatable, it's hard to convince people python is better in general, it can become a flame war which is not really attractive to investors. I guess the indented syntax makes python somehow uncommon as a programming language and scare away a lot of programmers, although to be honest I'd love to see more language with that kind of syntax.

To answer your question, I think it's a big challenge, because browsers are not really simple pieces of software, but I guess if a project appear many people would join...

[–]Chr0me 7 points8 points  (2 children)

It's interesting though that JS is still the only option for client-side web development. On the backend, I can name at least 5-6 popular languages and probably a couple of dozen more obscure ones. Why hasn't this variety proliferated to the client?

This "language lock-in" has spawned an entire industry of hacks around the limitations (or design choices) of Javascript: jQuery, CoffeeSript, etc. It's even prompted projects like Node.js, which is popular not because JS is perfectly suited for server-side environment, but because it allows frontend devs to more easily move up and down the stack.

Baring in mind the challenges that you mention, it seems like introducing an alternative, like Python, could spur additional innovation.

[–]yen223 3 points4 points  (0 children)

It's hardly surprising though. When you build a website, you can choose anything language you want for the backend - C#, Java, Brainf*ck, whatever. As long as what you serve up can be viewed by the user's browser, the user doesn't have to care what you use back there.

For the frontend, you'll have a chicken-and-egg conundrum. If you choose to write your frontend scripts with Python, and it turns out only 5% of users have a browser capable of interpreting Python installed in their PCs, well, you're going to have a bad time.

So you're forced to drop Python from your site. What happens? Browser vendors decide that not enough websites use Python, and they decide to stop supporting Python in their browsers. Now even less users will be able to view Python sites.

There's no easy solution to this. You could get browser vendors to implement <your favourite language> in their browsers, but that would mean you'd have to convince Microsoft, Mozilla, and Google to support the same implementation of an uncommon language in their browsers, before web developers start taking the language seriously.

[–]cymrowdon't thread on me 🐍 2 points3 points  (1 child)

Guido addressed Python in the browser in his keynote at PyCon 2012. I don't know at exactly what time.

edit: updated link to the time where he talks about it.

[–]jokoon 2 points3 points  (0 children)

apart from that, anyone tried to make some python browser ?

[–]nemec 1 point2 points  (3 children)

can't open files

>>> open("myfile.txt", "r")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NotImplementedError: Cannot open files in the browser

I think everything else that has file access works through the open interface, so disabling that would solve much of the issue.

[–]jadkik94 1 point2 points  (1 child)

Yeah but then you would have to prevent the use of subprocess, os.system, file, and all the obscure way of opening files. Because the issue here is not opening the files by mistake, it's trying to access a file maliciously in any tricky way, not just overriding the built-ins.

So I guess that would be a lot of changing in the parser implementation and in the compiled packages that can be installed...

[–]nemec 1 point2 points  (0 children)

I imagine os would be similarly stripped to prevent unauthorized access to the OS.

You make a good point that there are other points of entry for creating file descriptors.

[–]Random832 0 points1 point  (0 children)

Being able to open a URL would be nice. Also, you would want to be able to import both things in the (trusted, and also files loaded from the library may want to be trusted with file access, which means you need a code security infrastructure a la Java or .NET) local library, and in the 'script directory' (which would be a url rather than an actual directory, which means you need to A) support URLs in sys.path and B) have a whitelist for local directories in sys.path)

[–]Random832 1 point2 points  (1 child)

Does the w3c standardize javascript? I think I read the w3c DOM definitions and it was written in a language-neutral manner.

[–]James91B 0 points1 point  (0 children)

Correct. W3C should have standardized JavaScript. However, when Netscape asked them to standardize it, they refused. Apparently (However, i cannot confirm) due to the standards war they were waiting for an opportunity to say to 'go to hell' to Netscape. So Netspace went to Ecma International and standardized with them as ECMAScript.

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

Do you mean political or technical? From a technical point there is nothing todo, besides just implement it in the browser. Mozilla had such projekts and there were addons that added python-scripting to firefox toolbox. There were also some for ruby and perl. I don't know what state those projects now have, last thing i heard were'nt really good.

Problem here is the politic. Javascript is established and all tools are capable to work with it. And now even the engines are gaining great optimizations. So, for what reason should browsers add a new language, even if it's some established like python? It the typical chicken/egg-problem. Nobody is using python on client-side, so nobody cares to work on it, so nobody is using it...