Python - The Scripting Language

I am a newbie learning JavaScript to design web pages. Being new on the boat, I am finding it very hard to learn JavaScript. I have used Python extensively as a scripting language in my different projects.

We all now that Python is one of the most used languages.

Is there any chance that Firefox can use webpage-embedded Python to “talk” to Web pages? Now, I know that Python has its own disadvantages but think of the benefits we will have:

1.) 4.3 million Python Programmers brought to web development.

2.) Easy and aesthetically pleasing syntax of the lang.

3.) Availability of thousands of Python Libraries on the browser Firefox including Keras, BeautifulSoup, etc.

Will add more benefits as I get them.

I know some of the above advantages will not be available due to some big/small problems but I think that many of the libraries should remain intact if Firefox provides proper APIs to them.

Suggestions and Debates? Let’s do them!

Hello there! This is an interesting discussion.

Finding difficulty using JavaScript? We have a course for you: https://developer.mozilla.org/en-US/docs/Learn/JavaScript

Second, the idea of interpreting Python embedded on web pages on the client-side is not really possible in a traditional sense. You’d have to do loads of work to build code into web browsers to interpret Python, and make sense of what the code would actually do on web pages.

Or you’d have to build a JS library that could interpret Python and output results, which would be slooooooow and awful. It’s better to use the right tool for the right job, generally speaking.

One real way to achieve what I think you are saying you want would be to convert your Python code to wasm modules (see https://developer.mozilla.org/en-US/docs/WebAssembly). This would require someone to write a Python to wasm compiler, but this is a much easier proposition than building a Python interpreter into the browser! The toolchain for C++ to wasm and Rust to wasm is already there.

1 Like

What I am going to say, if started, will take a long period of development and testing.
Idea will seem absurd so bear with me…

Here is my idea:

How about we try to make a Gecko like engine but for Python?

The above idea will only make sense if Python gives us a very good upper hand over existing structures.

It doesn’t make much sense, in my opinion. I mean, Python is a very good language for doing application type things like manipulating text documents, accessing databases, and handling HTTP requests/responses.

It shares some functionality with JavaScript, like string manipulation, graphics manipulation, etc.

But it lacks a lot of important features that JavaScript has, such as the ability to manipulate the document object model and CSS, responding to web events, etc.

To make this work would not only require you to implement a new rendering engine, but also to make changes to the language itself.

Python is primarily a server-side programming language which means it is designed to run on servers. PHP, CGI. Perl etc are all server-side programming languages.

JavaScript is primarily a client-side programming language which means it is designed to run on clinet’s computer.

While there are hybrid versions like server-side JS (e.g. node.js), there are meant for totally different purposes.

There are also application-side programming languages too like C, C++, C#, etc

Reading your arguments, I have started thinking that it is a bad idea. JS wins!

For just the sake of it, let’s assume that somehow Python is equivalent to JS. What can be the advantages other than what I have mentioned in my first post?

But they are not equivalent. “C family” languages have a lot in common - datatypes, control structure, comparison operators, etc. etc. - but they also have differences unto themselves. And perhaps most importantly, they have different strengths and weakness and uses that can be the deciding factor as to whether or not they are the “best tool for the job”.

True, I think that many times functionality can be supplemented by using addons, extensions, libraries, polyfills, etc. but it makes more sense to me to use what needs the least help to do something.

Personal preference often is a major deciding factor, but in terms of Python vs. JavaScript I think the difference is just too great to think of them as alternative options.

What could be done however, is to propose that JavaScript “steal” the “good stuff” from other languages. eg. fat arrow functions.

So if you find yourself thinking “Python lets me write code like this, I wish JavaScript had that syntactic sugar” there would be no harm in suggesting it be adopted. Who knows? it might just happen.

1 Like

I would like to take this discussion in a different direction: Instead, of a technical solution (put Python in browsers, make JS more like Python), my approach is:

How can we make it easier to learn JavaScript?

@kool989, what aspects of JavaScript do you find hard to learn, coming from Python? Personally, coming from languages with class-based inheritance (C++, Java, Python), I had a hard time wrapping my head around prototype-based inheritance in JavaScript (still not sure I’ve absorbed it completely).

Since this is a forum for MDN Web Docs, we can use feedback like this to improve or expand the JavaScript tutorials.

2 Likes

Disclaimer: I have not yet used MDN Docs for JS.

May be it is my bias towards JS because of easiness of Python.
I found JS hard when I first saw those fat arrow functions.
Coming from Python, I did not know various useful functions like “getElementById()” which infuriated me. It is my bias against JS which made it hard.
Knowing functions of a new lang is what “learning-it” is all about.

I will surely look into MDN Docs and then If I find any good suggestion, I will post in this thread.

Edit 1: I liked @jswisher’s idea about turning the discussion to new direction. Awesome.

I know I’m a bit late but I’ve been playing lately with Pyodide and it’s fantastic. It’s a Python distribution for the browser. It makes it possible to install and run Python packages in the browser. It also comes with a robust Javascript ⟺ Python foreign function interface so that you can freely mix these two languages in your code with minimal friction.