from : Micro reading https://www.weidianyuedu.com
Python It's so hot now , Has developed into a very common language , From entry-level players to professional data mining 、 Scientific Computing 、 The image processing 、 Artificial intelligence ,Python All of them can do . Will it be the programming language of the future ? Is it a perfect programming language ?
What makes Python It's so popular now
Python The success of now Stack Overflow trend On , This trend measures the number of tags in posts on the platform . Whereas Stack Overflow The scale of , So it's a good indicator of the popularity of programming languages .
Stack Overflow A snapshot of the tags in various programming languages .
Even though R Language has been stagnant in the past few years , And many other programming languages are steadily falling , but Python The growth seems unstoppable . Almost all Stack Overflow The problem is 14% Marked as “Python”, And the trend is on the rise .
There are several reasons for this :
It's ancient
Python As early as 20 century 90 The time has come . It doesn't just mean that it has enough time to grow , It also has a huge support community .
therefore , If you're using Python What's wrong with coding , You are likely to pass through Google A search will solve . It's because someone has had the same problem as you , And wrote down some useful things .
It's very friendly to beginners
It's not just a fact , Because it's been around for decades , Let programmers have time to write excellent tutorials . what's more ,Python The grammar of is very easy to understand .
First , There is no need to specify the data type . You just need to declare a variable ;Python It will be understood from the context that it is an integer 、 Floating point value 、 Boolean or something else . This is for beginners , It's a huge advantage . If you have ever used C++ When programming , You'll know how frustrating it is that your program can't be compiled , Just because you've changed floating-point numbers to integers .
If you've ever read at the same time Python and C++ Code , You will know Python How easy it is to understand . Even though C++ English is taken into account in the design , But with Python Code comparison , It's still quite difficult to read .
It has a wide range of uses
because Python It's been around for so long , Developers have created packages for a variety of potential requirements . Now? , You can find packages for almost every purpose .
Want to calculate the number 、 Vectors and matrices ?NumPy It's what you're looking for .
Want to do technical and engineering calculations ? Please use SciPy.
Want to be big in data processing and Analysis ? Then try it. Pandas Well .
Want to start with AI ? Then why not use Scikit-Learn Well ?
No matter what kind of computing task you want to do , There are corresponding Python software package . This makes Python Has been at the forefront of development , It can be seen from the hot wave of machine learning in the past few years .
Python The shortcomings and whether they will be fatal
Based on the previous explanation , You can imagine Python It will continue to flourish in the next few years . however , Like all technology ,Python There are also its weaknesses . I will introduce the most important defects one by one , And evaluate whether these defects are fatal .
Speed
Python Very slowly . Really? , Very, very slow . On average, , Use Python The time required to complete a task , It's in any other programming language 2~10 times .
What caused this situation There are many reasons . One of them is , It's a dynamic type , remember , You don't need to specify data types as you would in other programming languages . This means a lot of memory needs to be used , Because the program needs to reserve enough space for every variable that it can work in any case . And a lot of memory usage means a lot of computing time .
Another reason is ,Python Only one task can be performed at a time . This is the result of flexible data types :Python You need to make sure that each variable has only one data type , And parallel processes can mess up this .
by comparison , General Web Browsers can run dozens of different threads at the same time . Besides , There are other theories .
But in the final analysis , These speed problems don't matter . Computers and servers have become so cheap , So we're talking about a fraction of a second . actually , End users don't care if their application is 0.001 Seconds or 0.01 Seconds to load .
Scope
first ,Python Of Scope is dynamic . This basically means , To evaluate the expression , The compiler first searches the current block , Then search all the calling functions in turn . That's why most modern programming languages use static scopes .
Python Tried to transition to static scope , but Screwed up . Usually , Internal scope ( For example, a function in a function ) Ability to view and change external Complete collection of model articles Scope . But in Python in , Internal scopes can only see external scopes , And can't change them , This leads to a lot of confusion .
Lambda
Even though Python With all the flexibility , but Lambda Its use is still quite limited .Lambda Can only be Python The expression in , It can't be a statement .
On the other hand , Variable declarations and statements are always statements . It means Lambda Not for them .
The difference between expressions and statements is quite arbitrary , It doesn't exist in other programming languages .
Whitespace makes code more readable , But it's less maintainable .
stay Python in , You can use spaces and indents to represent different levels of code . This makes it visually attractive , It's more intuitive to understand .
Other programming languages , Such as C++, More dependence on curly braces and semicolons . Although it may not be visually appealing , Not very friendly to beginners , But it makes the code easier to maintain . For larger projects , This method is more useful .
image Haskell Such a new language solves the problem : They depend on Spaces , But there's another syntax for those who want to not use spaces .
Mobile development
We are witnessing the shift from desktop computers to smartphones , Obviously , We need a powerful language to develop mobile software .
But use Python Not many mobile applications have been developed . however , That doesn't mean it can't — There is one named Kivy Of Python Software package is specially used to develop mobile applications .
however Python Mobile development is not considered in the design . therefore , Even if it may produce poor results for basic tasks , Your best choice is to use a programming language created specifically for mobile development . Some widely used mobile programming frameworks include React Native、Flutter、Iconic and Cordova.
Just to be clear , Laptops and desktops should continue to exist for many years to come . however , Because mobile devices already have more traffic than desktops , So I can say for sure , Learn to Python Not enough to be an experienced all-around Developer .
Runtime error
Python The script is not compiled first and then executed . contrary , It compiles every time it executes , therefore , Any coding errors are displayed at run time . This leads to poor performance 、 Time consuming , And a lot of testing is needed . such as , A lot of tests .
This is especially suitable for beginners , Because testing can teach them a lot . But for experienced developers , Must use Python Debugging complex programs can make them go wrong . The lack of this performance is in Python The biggest factor in setting a timestamp on .