Home >Backend Development >Python Tutorial >Life is short, I use Python

Life is short, I use Python

伊谢尔伦
伊谢尔伦Original
2016-11-25 09:56:571205browse

Python is my favorite language, it is simple, beautiful and easy to use. Two days ago, I passionately promoted the benefits of Python to my friends.

 “Okay, I admit that Python is good, but why is it called Python?”

 “Well, it seems to be the name of a TV series.”

 “Then is the Guido you are talking about American?”

 “He Switched from Google to work at Dropbox, but his name looks like a Dutch one. "

  "Are you sure you are familiar with Python? "

  So to avenge my shame, I took the time to investigate the history of Python. I saw the origin of many functions in Python and the design philosophy of Python, the evolutionary history of a programming language, and the wonderful connection between Python and the open source movement. From the history of Python, we can get a glimpse of the ideas and achievements of open source development.

 This can also be used as the prelude to the quick Python tutorial I wrote.

 Origin

 The author of Python, Guido von Rossum, is indeed a Dutchman. In 1982, Guido received a master's degree in mathematics and computing from the University of Amsterdam. However, although he was a mathematician, he enjoyed computers even more. In his words, despite having dual qualifications in mathematics and computers, he always tends to do computer-related work and is keen on doing anything related to programming.

 At that time, Guido came into contact with and used languages ​​such as Pascal, C, and Fortran. The basic design principle of these languages ​​is to make machines run faster. In the 1980s, although IBM and Apple had launched a wave of personal computers, the configuration of these personal computers was very low. For example, the early Macintosh only had an 8MHz CPU frequency and 128KB of RAM. A large array could fill up the memory. The core of all compilers is to optimize so that the program can run. In order to increase efficiency, the language also forces programmers to think like a computer so that they can write programs that are more in line with the taste of the machine. In that era, programmers were eager to squeeze every inch of computer power with their hands. Some people even think that C language pointers are a waste of memory. As for dynamic typing, automatic memory management, object-oriented... Don't think about it, it will paralyze your computer.

This kind of programming makes Guido feel distressed. Guido knows how to write a function in C language, but the entire writing process takes a lot of time, even though he already knows exactly how to implement it. His other option is the shell. The Bourne Shell has existed as an interpreter for UNIX systems for a long time. UNIX administrators often use shells to write some simple scripts to perform some system maintenance tasks, such as regular backups, file system management, etc. The shell can be like glue that connects many functions under UNIX together. Many programs with hundreds of lines in C language can be completed in just a few lines in the shell. However, the essence of the shell is to invoke commands. It's not really a language. For example, the shell does not have numeric data types, and addition operations are very complicated. In short, the shell cannot fully mobilize the computer's functions.

 Guido hopes to have a language that can fully call the functional interface of the computer like C language, and can be easily programmed like shell. ABC language gave Guido hope. ABC was developed by the Institute of Mathematics and Computing in the Netherlands. Guido worked at the institute and was involved in the development of the ABC language. ABC language is for teaching purposes. Unlike most languages ​​at the time, the goal of the ABC language was to "make users feel better." ABC Language hopes to make the language easy to read, easy to use, easy to remember, and easy to learn, and to stimulate people's interest in learning programming. For example, the following is an ABC program from Wikipedia. This program is used to count the total number of words appearing in the text:

HOW TO RETURN words document:
 
   PUT {} IN collection
 
   FOR line IN document:
 
      FOR word IN split line:
 
         IF word not.in collection:
 
            INSERT word IN collection
 
   RETURN collection

  HOW TO is used to define a function. A Python programmer should easily understand this program. ABC language uses colons and indentation to represent blocks of programs. There is no semicolon at the end of the line. There are also no parentheses () in the for and if structures. Assignment uses PUT instead of the more common equal sign. These changes make the ABC program read like a text.

Although it has good readability and ease of use, the ABC language ultimately did not become popular. At that time, the ABC language compiler required a relatively high-end computer to run. The users of these computers are usually computer proficient, and they consider the efficiency of the program more than the difficulty of learning it. In addition to hardware difficulties, the design of the ABC language also has some fatal problems:

 Poor scalability. ABC language is not a modular language. If you want to add functions to the ABC language, such as graphical support, you must change many places.

  Cannot perform IO directly. ABC language cannot directly operate the file system. Although you can import data through methods such as text streams, ABC cannot read and write files directly. The difficulty of input and output is fatal to computer languages. Can you imagine a sports car with doors that can't be opened?

 Excessive innovation. ABC uses natural language to express the meaning of the program, such as HOW TO in the above program. However, for programmers, they are more accustomed to using function or define to define a function. Likewise, programmers are more accustomed to using the equal sign to assign variables. Although the ABC language is very special, it is also very difficult to learn.

Difficulty in spreading. The ABC compiler was large and had to be saved on tape. When Guido visited, he had to have a large tape to install the ABC compiler for others. In this way, it is difficult for ABC language to spread quickly.

 In 1989, in order to pass the Christmas vacation, Guido started writing a compiler for the Python language. The name Python comes from Guido’s beloved TV series Monty Python’s Flying Circus. He hopes that this new language called Python can meet his ideal: to create a language between C and shell that is comprehensive, easy to learn, easy to use, and scalable. As a language design enthusiast, Guido has already tried to design languages. This time, it was nothing more than a pure act of hacking.

 The birth of a language

 In 1991, the first Python compiler was born. It is implemented in C language and can call C language library files. From its birth, Python has had: classes, functions, exception handling, core data types including tables and dictionaries, and a module-based expansion system.

 A lot of Python syntax comes from C, but it is also strongly influenced by the ABC language. Some rules from the ABC language are controversial to this day, such as forced indentation. But these syntax rules make Python easy to read. On the other hand, Python smartly chooses to obey some conventions, especially those of the C language, such as reverting equal sign assignment. Guido believes that if something is established based on "common sense", there is no need to get too hung up on it.

 Python has paid special attention to scalability from the beginning. Python can be extended on multiple levels. At a high level, you can import .py files directly. Under the hood, you can reference C libraries. Python programmers can quickly use Python to write .py files as expansion modules. But when performance is an important factor to consider, Python programmers can go deep into the bottom layer, write C programs, compile them into .so files and introduce them into Python for use. Python is like building a house with steel. First define the large frame. Programmers can expand or change quite freely under this framework.

 The original Python was completely developed by Guido himself. Python is popular among Guido's colleagues. They provide quick feedback and participate in Python improvements. Guido and some colleagues form the core team of Python. They spend most of their spare time hacking Python. Subsequently, Python expanded beyond the institute. Python hides many machine-level details and leaves them to the compiler to handle, and highlights logical-level programming thinking. Python programmers can spend more time thinking about the logic of the program instead of specific implementation details. This feature attracts a large number of programmers. Python became popular.

Life is short, I use python

Times make heroes

We have to pause our Python time and take a look at the ever-changing computer industry. In the early 1990s, personal computers began to enter ordinary households. Intel released the 486 processor, and Windows released a series of window systems starting with window 3.0. Computer performance is greatly improved. Programmers began to pay attention to the ease of use of computers, such as graphical interfaces.

Life is short, I use Python

Windows 3.0

  Due to the improvement in computer performance, the world of software has also begun to change. The hardware is sufficient for many personal computers. Hardware manufacturers are even eager for the emergence of high-demand software to drive upgrading of hardware. C++ and Java became popular one after another. C++ and Java provide object-oriented programming paradigms and rich object libraries. At the expense of a certain amount of performance, C++ and Java have greatly increased program output. The ease of use of the language has been taken to a new level. We also remember that an important reason for the failure of ABC was the performance limitations of the hardware. In this respect, Python is much luckier than ABC.

Another change that is happening quietly is the Internet. The 1990s was still the era of personal computers. Windows and Intel dominated the world with PCs, and they were very popular for a while. Although the Internet-based information revolution has not yet arrived, many programmers and experienced computer users are already frequently using the Internet to communicate, such as using email and newsgroups. The Internet has greatly reduced the cost of information exchange. A new software development paradigm is beginning to gain popularity: open source. Programmers use their spare time to develop software and open source code. In 1991, Linus released the Linux kernel source code on the comp.os.minix news group, attracting a large number of hackers to join. Linux and GNU work together to form a vibrant open source platform.

 Hardware performance is not a bottleneck, and Python is easy to use, so many people are turning to Python. Guido maintains a maillist, and Python users communicate through email. Python users come from many fields, have different backgrounds, and have different needs for Python. Python is quite open and easy to expand, so when users are not satisfied with the existing functions, it is easy to expand or transform Python. These users then send their changes to Guido, who decides whether to add the new features to Python or the standard library. It would be a great honor if the code could be incorporated into Python itself or the standard library. Because of Guido's supreme decision-making power, he is known as the "Lifelong Benevolent Dictator."

 Python is called "Battery Included", which means that it and its standard library are powerful. These are contributions from the entire community. Python developers come from different fields, and they bring the advantages of different fields to Python. For example, the regular expressions in the Python standard library refer to Perl, while functions such as lambda, map, filter, and reduce refer to Lisp. Some features of Python itself and most of the standard library come from the community. The Python community continues to expand and has its own newsgroup, website, and fund. Starting from Python 2.0, Python has also changed from a maillist development method to a completely open source development method. A community atmosphere has been formed, work is shared by the entire community, and Python has also achieved faster development.

 To this day, the framework of Python has been established. The Python language organizes code with objects as the core, supports multiple programming paradigms, uses dynamic types, and automatically recycles memory. Python supports interpretation and operation, and can call the C library for expansion. Python has a powerful standard library. Since the standard library system has stabilized, the Python ecosystem has begun to expand to third-party packages. These packages, such as Django, web.py, wxpython, numpy, matplotlib, and PIL, upgrade Python into a species-rich tropical rainforest.

Revelation

Python advocates elegance, clarity, and simplicity. It is an excellent and widely used language. Python ranks eighth in the TIOBE rankings. It is the third largest development language of Google, the basic language of Dropbox, and the server language of Douban. The development history of Python can be used as a representative and brings me a lot of inspiration.

 In the development process of Python, the community plays an important role. Guido thinks that he is not an all-round programmer, so he is only responsible for formulating the framework. If the problem is too complicated, he will choose to go around it, that is, cut the corner. These problems are ultimately solved by others in the community. The talent in the community is extremely rich. Even things that are slightly distant from development, such as creating websites and raising funds, there are people who are willing to handle them. Today's project development is becoming more and more complex and larger. Cooperation and an open mind have become the keys to the ultimate success of the project.

 Python has learned a lot from other languages, whether it is ABC that has entered history, or C and Perl that are still in use, and many other languages ​​​​not listed. It can be said that the success of Python represents the success of all the languages ​​it draws from. Similarly, Ruby borrows from Python, and its success also represents the success of Python in some aspects. Every language is a hybrid, with its strengths and weaknesses. At the same time, the judgment of "good or bad" of a language is often subject to external factors such as platform, hardware, era, etc. Programmers experience many language battles. In fact, if you accept various languages ​​with an open mind, maybe one day programmers can mix their own languages ​​like Guido.

Regardless of the future fate of Python, the history of Python is already an interesting novel.


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
Previous article:Python object-orientedNext article:Python object-oriented