4 key features that you will not see in the Python programming language
soltani python

4 key features that you will not see in the Python programming language

Python programming language will probably not have some features for several years, in this article we will talk more about these features in Python programming language.

The Python programming language has many attractive features, among which one can mention the ease of using this language, a wide range of powerful libraries, a large community of users and developers, etc. However, this language is still missing some very important elements. Some features found in other programming languages make it easier for businesses and developers to work, but those features won't be coming to Python any time soon. In the following, we introduce four important features that currently do not exist in the Python programming language. At least two of these features you will never see in this language, and the others will take at least several years to be added to this language. In fact, we continue to talk about what is blocking the way for these features to be added to Python, or what is needed to include them in future versions of Python.


A statically typed and compiled version of the Python programming language

Some developers dream of a version of the Python programming language that uses statically typed to compile to native machine code. Anyway, flexible typing is the origin of many codes that are written in Python programming language, and statically typed can put an end to this issue. In addition, you should be careful that the statically typed feature can allow developers to include better guarantees in their code. So what is the issue that this feature is not added to Python?


Although the Python language has many capabilities in the field of typing, these features are designed to make the language more compatible for static analysis during code editing and using linting tools. Only third-party projects like pydantic use typing tools at runtime. Be careful that the Python language runtime does not use these tools by itself.Convert Python to compiled version

One of the explicit goals stated in PEP 484 is the proposal to upgrade Python to the type hinting version. Be careful that this language will remain a dynamically typed language and the authors and creators of this language are not interested in forcing type hinting in this language. Developers who really want a statically-typed version of the language can use Cython or mypyc, but even these projects will experience problems and challenges. Regarding Cython, you should know that the greatest increase in performance is due to the use of C types and structures and the reduction of the use of the Python language runtime. Simply put, it would be very difficult to compile the Python programming language quickly without compromising its dynamics. Of course, you should be careful to remove parts that do not need to be dynamic, separating and speeding up these parts can be very simple and convenient.

Lambdas that can be used on multiple lines

Lambda expressions used in the Python programming language or anonymous functions are intentionally limited in this language. They only allow you to define a specific expression as the body of your function (note that an expression here means anything to the right of the = assignment sign). Developers who come to Python from languages such as JavaScript often request that the ability of multi-line anonymous functions be added to this programming language.

Reasons for not adding multi-line lambdas

The creator of this programming language, Guido van Rossum, long ago abandoned the idea that multi-line lambdas could be used in this language. In 2006, through an email, he explains the reason for not using this type of lambdas as follows:

Lambdas defined in a few lines add very little power to the Python programming language, but at the cost of making Python a less readable language. Currently, there is no suitable syntax for use in this situation that fits nicely with other syntactic designs of this programming language. It takes very little effort to convert a multi-linear lambda into a complete function, which may be another reason for not using multi-linear lambdas. It goes without saying that a not-so-bright future for multi-line lambdas in Python can be imagined.

Python programming language without GIL

The Global Interpreter Lock function, which is also called GIL for short, has caused many problems for Python programming language enthusiasts for a long time and has not satisfied them in any way. The GIL is a tool that coordinates various activities in the Python runtime to serialize access to various objects for you and manage global state for you. A very important disadvantage of the GIL is that it effectively turns the Python runtime into a single thread. So if you as a developer want to do real parallelization with Threads you need to start different versions of the Python interpreter and run separate Threads on each of them. GIL-free Python programming language can provide developers with more optimal parallelism and improve performance.

Why does it seem unlikely to remove the GIL feature from Python?

Various proposals have been made to remove the GIL from the Python programming language. Most of these suggestions break backwards compatibility in the Python programming language or make Python slower to perform single-threaded operations. One of the efforts that have been made in this field was GILectomy, which caused many performance problems in this programming language. Python 3.x reintroduced the GIL to improve its integrated performance, but did not remove the feature at all to maintain backward compatibility.

Final remarks about GIL

Due to many concerns in this field, GIL may continue to work in this language, but facilities should be added to improve its performance. One way to do this is to allow better parallelization in the Python runtime and to run multiple interpreters at the same time. To realize this proposal, significant changes in the internal parts of this programming language are needed, among which we can mention the revision of parts of the C language API in Python. Be careful that many third-party modules in this language depend on the C language API and must be kept up to date.


A more recent proposal in this regard is PEP 684, which develops the idea of multiple interpreters so that each sub-interpreter can use its own GIL.


A JIT compiler native to the Python programming language

One of the proven ways to increase the speed of the Python programming language while maintaining the flexibility of this language is to use a just-in-time compiler, which is also called JIT for short. Just-in-time compilation includes code analysis at run time and its completeness is also optional. That is, your codes will be compiled based on the behavior they show at runtime

Problems with JIT compilers

JIT compilers already exist in the Python programming language. PyPy is the most common and best developed example of it, which is used in the structure of programs and long-term projects. This tool makes the connection with the server faster and the performance of your program is optimized to a great extent. However, JIT still causes problems in Java, which has led to many proposals in this field. A native compiler in this field can solve many of these problems, but will this happen in the future? This is what many people are hoping for.

要查看或添加评论,请登录

Farnoosh Soltani的更多文章

社区洞察

其他会员也浏览了