Home>Article>Web Front-end> Why Python is like JavaScript

Why Python is like JavaScript

醉折花枝作酒筹
醉折花枝作酒筹 Original
2021-07-15 14:43:59 1977browse

The reasons are: 1. Js operators are similar to those in Python; 2. Js data types are similar to those in Python; 3. The native syntax of Js and Python supports iterators and generators; 4. Proxy and Reflection in JS are rewritten through "__xxx__" operators in Python.

Why Python is like JavaScript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

First of all, JavaScript itself is a hybrid that draws on many other languages. Brendan Eich, the founder of JavaScript, once jokingly called it "the product of a one-night stand between C language and Self language." Secondly, with the development of modern programming languages, convergence is definitely a trend. After all, "perfect languages are always similar, and imperfect languages have their own imperfections."

However, it should be said that JavaScript and Python is fundamentally different in its implementation mechanism. For example, the former is based on the Self language and is based on prototype (Prototype), while the latter is based on class (Class). I think the reason why the questioner feels that JavaScript is becoming more and more like Python is mainly because both of them provide many similar "syntactic sugars", such as:

(1)(.. in JavaScript.. .operator) and (* and ** operators in Python)

(2) (Set and Map data types in JavaScript) and (Set and Dictionary data types in Python)

(3)The native syntax of JavaScript and Python supports iterators and generators

(4)(Proxy and Reflection in JavaScript) and (rewriting operators through __xxx__ in Python)

and so on, especially some of the new grammatical features after ES2015, it really feels like many of them are borrowed from Python. But it can also be said that a mature and complete scripting language will eventually provide these language features, not necessarily who learns who, but may be a spontaneous convergence driven by development needs and development concepts, just like birds and bats Each evolved wings - this is called convergent evolution in biology.

Let’s talk about the question of “perfect languages are always similar”, then why not unify them into the same language. I think this has a lot to do with the language ecology. In the process of development, some languages have accumulated a large number of third-party libraries and problem solutions in a certain field, and the Matthew effect gradually appears, making it difficult to solve problems in this field. The language only needs to introduce library functions, while some languages require long and lengthy codes to be written.

It’s not that a desert cannot be turned into an oasis, but the feasibility of something must not only consider the feasibility of natural laws but also the feasibility of economic costs. Take the front-end as an example. If you use Python on the front-end, many front-end libraries and many blogs will have to be written again. Go to MDN to see the number of front-end APIs provided by JavaScript, and go to CSDN to see the number of related blogs, and you will know how vast the project is. Although WebAssembly is now launched, allowing other languages to run on the browser, JavaScript APIs still need to be called.

The diversity evolved naturally may seem chaotic, but it is often better than the unity conceived by humans.

[Recommended learning:javascript advanced tutorial]

The above is the detailed content of Why Python is like JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn