Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the reasons for the major defects in Python?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you that there are major defects in Python reasons, I believe that most people do not understand, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Reason 1: incompatibility between versions

After installing Linux, it is likely to install multiple versions of Python by default, possibly with Python2 and Python3, or even more piecemeal versions, such as 3.5 or 3.7.

There's a reason for this: Python3 is not fully compatible with Python2, and some other versions have obvious flaws in this area-- backward compatibility (backwards compatibility, also known as backward compatibility).

So Ubuntu installs both Python2 and Python3 because the core features of these versions are different.

The lack of backward compatibility and separation of versions is usually an early warning of decline. Commodore created the first home computer (long before IBM PC or Apple). However, Commodore PET is not compatible with subsequent Commodore CBM computers, and CBM is not compatible with VIC-20,Commodore-64,Amiga and so on. As a result, users either spend a lot of time directing code from one platform to another, or they simply abandon that platform-Commodore is a lesson. When users choose to abandon the platform, it is doomed to disappear.

Similarly, Perl used to be very popular. But when Perl3 came out, it wasn't fully backward compatible with Perl2 code. Next up is Perl4. When Perl5 came out, many people chose to switch to other, more stable programming languages. So today, only a small number of people are actively using Perl to maintain existing Perl projects, and any other major new Perl-based projects have never emerged.

Similarly, Python designed a different code island for each version. The community has been dragging these old versions, so you end up with old, outdated Python code, because no one wants to take the time to import it to the latest version.

As far as I know, no one creates new code on Python2, but we keep it alive because no one directs the required code to Python3.x. On the official Python website, these documents are proactively maintained and can be used for Python 2.7,3.5,3.6,3.7Mel-because they cannot discard old code. Python moves forward like a zombie in a programming language-a walking corpse.

Reason 2: the installation is too troublesome.

Generally speaking, the latest stable version is what you get directly after apt, yum, and rpm.

But if you don't know what version of apt-get install python', it is, it may not be compatible with all the code you need. So you need to specify the Python version when you install.

There was a project that required Python3.5 (the latest version at the time), but I ended up with a bunch of versions on my computer: Python2, Python2.6, Python3, and Python3.5. Two are from the operating system, one is for the project installation, the other is because I installed some unrelated software.

Although they are all "Python", they are not exactly the same.

If you want to install Python packages, you should use "pip" (Pip stands for "Pip Installs Packages"). But since there are many versions of Python on the system, you must remember to use the correct version of pip. Otherwise, 'pip' may run' pip2' instead of the 'pip3.7'' you need. (if the name does not exist, you need to specify the actual installation path of pip3.7. )

I was told by a friend that I needed to configure the environment so that everything could use Python 3.5. This approach did work, but it didn't last long because I started another project that required version 3.6 of Python. It's a bit complicated to say that two concurrent projects have two different versions of Python--emmmm.

The pip installer places the files in the user's local directory. You can't use pip to install system-wide libraries, and Gawd will prevent you from making the mistake of running 'sudo pip', because it will mess up the whole computer!

By the way, who maintains these pip modules? The answer is community. In other words, there is no clear owner and no mandatory responsibility. Earlier this year, a version of PyPi had a backdoor where SSH credential theft occurred, but I'm not surprised because the community repository is simply not trustworthy. For the same reason, I don't use Node.js and npm either.

Reason 3: troublesome grammar problems, poor readability due to the use of spaces in the scope

I am a strong believer in readable code. At first glance, Python seems to be very easy to read, but when you start making a large code base, this readability will diminish.

Other programming languages, such as C, Java, JavaScript, Perl, and PHP, use {} to represent scope; List uses (). Python uses spaces. If you need to define a scope for a complex code, then you indent the following lines of code, and when the indentation terminates, the scope ends.

The Python manual says you can use any number of spaces or tabs to define the range. However, use four spaces for each indent! If you want to indent twice to nest, you have to use eight spaces!

The Python community has standardized this term, although it does not appear in the Python manual. The examples in the documentation say that you can use TAB, "TAB+1 spaces", and so on. But the community is crazily paranoid about four spaces! So, unless you plan to never show your code to anyone else, use four spaces for each indent.

When I first saw the Python code, I thought it might be a good idea to use indentation to define the scope. As a matter of fact, I am so naive that this is simply a big weakness.

Deep nesting is possible, but each line of code becomes so wide that it has to wrap in a text editor. Long functions and long conditional operations can make the beginning and end difficult to match. I pity people who miscalculate the number of spaces (such as losing only three spaces instead of four), because such errors take hours to debug and track.

My debug code is used to not indenting, so I can quickly browse through the code and easily identify and delete debug code when I'm done.

But what about Python? If you make an indent error, you will report an error.

Reason 4: maverick way of loading libraries

Most programming languages have ways to include other blocks of code. For C, it is "# include". For PHP, there are 'include','include_once','require'' and 'require_once'. For Python, it is "import".

Python's import allows you to import an entire module, part of a module, or specific functionality in a module. But finding ways to import code blocks is troublesome. Using C, just look directly at / usr/include/*.h. Python is available? It's best to use 'python-v' to list all the locations, and then search for every file in each directory and subdirectory in the list. This is really troublesome.

The import feature also allows users to rename imported code, which basically defines a namespace. At first glance, this seems good, but it will eventually affect readability and long-term support. The renaming module is perfect for small scripts, but it's really bad for large programs. Such an operation, "import numpy as n", should be killed.

But that's not the worst part. For most languages, including code really just means including code. Some languages, such as object-oriented C +, can execute code. Similarly, some PHP code may define global variables, so an import can run the code, but this is generally considered a bad practice. By contrast, many Python modules contain initialization functions that run during import. You don't know what's running, you don't know what it's doing, you don't even know it. Unless there is a namespace conflict, it will take you a long time to find out why.

Reason 5: keywords and library names are "unique"

In all other programming languages, arrays are called "array". In Python, arrays are called "list". In other languages, associative arrays are sometimes called 'hash' (Perl), but they are called' dictionary'in Python. Python does not seem to use the terms commonly used in computer and information science.

Then comes the name of the library. Look at these names, PyPy, PyPi, NumPy, SciPy,SymPy, PyGtk, Pyglet,PyGame. (yes, the first two names sound exactly the same, but their functions and uses are very different. (I know "py" stands for Python. But can't these two letters be fixed at the beginning or end of the library?

And some common libraries do not follow this so-called "Py" naming convention. Such as matplotlib, nose, Pillow, and SQLAlchemy. Although you can see some of the library's functions from some naming (for example, "SQLAlchemy" contains SQL, so it may be a SQL interface), many names are just randomized words. If you don't know what "BeautifulSoup" is for, can you tell from the name that it is a HTML / XML parser? (by the way, the documentation for the BeautifulSoup library is complete and easy to use. If every Python module were so easy to use, I wouldn't complain so much here. Unfortunately, this is an exception, not the norm. The documents in most Python libraries are awful. )

Overall, I think Python's naming of libraries is very confusing and lacks the principle of consistency. I always feel that there is this kind of rule confusion in the naming of open source projects. Unless you know the project, you can't tell from the project name at all. Unless you know what you are looking for, you will probably never find what you are looking for. Judging from the naming of most Python libraries, I am more convinced of this view now.

Reason 6: there are a little more other "unique" points.

Every language has its eccentricities. In C, using & and * to access address spaces and values is a strange nomenclature. C also has variable addition and subtraction controls such as "+" and-- ". In the Bash language, backslashes are required when referring to special characters such as parentheses and periods of regular expressions.

There is a compatibility issue with JavaScript (not every browser supports all useful features). But Python has more oddities than any other language I've ever seen. Take a string as an example:

In C, use double quotation marks for strings and single quotation marks for characters.

In PHP and Bash, both types of quotation marks can be used for strings. However, you can embed variables in a string when using double quotes. By contrast, strings enclosed in single quotation marks are literal. Any name similar to an embedded variable cannot be extended.

In JavaScript, there is really no difference between single and double quotes.

In Python, there is no difference between single and double quotes. However, if you want a string to span lines, you need to use triple quotes "string"or"''string'''. If you want to use binaries, you need to use b (bounded binaries) or r (raster raw') to select strings first. Sometimes you need to use str (string) for string conversion, or use string.encode (' utf-8') to convert it to utf8.

If you think the =, =, and = = symbols are a little weird in PHP and JavaScript, wait until you use quotes in Python.

Reason 7: the way of assignment is weird

Most programming languages pass function parameters by value. If the function changes the value, the result does not pass the callback code. But Python is different. Python executes the function using the pass-by-object-reference parameter by default. This means that changing the source variable may eventually change the value.

This is one of the major differences between program-oriented, function-oriented, and object-oriented programming languages. If each variable is passed through an object reference, and any change to the variable results in a change in the value of the variable everywhere else, you can also use global variables to handle everything. Calling the same object with a different name does not change the value of the object, so the object is actually global. There is an old saying among C language programmers that global variables are evil and should not be used.

In Python, variables must be passed by value. "a = b" simply specifies another name for the same object space and does not assign the value of b to a. If you want to assign a value, you need to use the copy function. The usual format is "a = b.copy ()". However, please note that I said "usually". Not all data types can be assigned in this way, and some functions may be incomplete. You need to use a separate library called "copy": "a = copy.deepcopy (b)".

Reason 8: local program naming is easy to be confused

It is a common programming technique to name programs according to the libraries or functions used. For example, I am testing a screen capture program using the C language library named "libscreencapture.so". The program I call might be named "screencapture.c" and compiled as "screencapture.exe".

This naming works well if you use languages such as CJR, Java, JavaScript, Perl, PHP, etc., because the programming language can easily distinguish the repository from the local program, because their paths are different. But if you are using Python, never name it that way.

Why? Python always assumes that the user imports local code first. If I have a program called "screencapture.py" that uses "importscreencapture", it will import itself instead of the system library. At the very least, the local program needs to be named "myscreencapture.py" to avoid this error.

Of course, there are so many complaints, but Python is not useless.

Python is a very popular language with a large number of users. I have some friends around me who like Python very much, which is their preferred programming language. I have discussed these issues with them over the years, and each time they nodded in agreement. They do not deny that Python does have these problems, but feel that these shortcomings are not enough for them to abandon Python.

My friends often refer to all the cool Python libraries that exist in programming. I also think some libraries are really useful. For example, BeautifulSoup is one of the best HTML parsers I've ever used, NumPy makes multidimensional arrays and complex mathematical processes easier to implement, and TensorFlow is very useful for machine learning. However, I will not create a monolithic program in Python because I like TensorFlow or SciPy. For the convenience of some libraries, the loss outweighs the gain by abandoning program readability and maintainability.

The above is all the contents of this article entitled "what are the reasons for the major defects in Python?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report