Python. A language that makes it easy to think

Hello, Habr!



We can pre-order the long awaited second edition of Simple Python . The translation of the first edition was released in 2016 and remains among the bestsellers to this day.







Since we are convinced that Python is the best programming language for beginners, as well as for working with data science and machine learning, today we offer you the translation of several worldview post from the Dropbox website, where Guido van Rossum ended his career - about the meaning and indispensability of the Python language.



Nothing characterizes the 21st century more than the pervasive influence of programming. Almost everything that we do, especially at work, is done through a monitor, done through a monitor, which displays the results of colossal computational work, which we today take for granted. For those 99.7% of the human race who are not involved in programming, all this happens as if by magic. As the great science fiction writer Arthur Clarke noted, "Any sufficiently advanced technology is indistinguishable from magic."



Of course, this is not magic. But programming is both a complex and multi-level process, the size of code bases in serious technology companies is measured in millions of lines of code. When you think about how a real system can be implemented at the code level, you think about the complex interplay of different functions over time. Your code may be more or less complex at the level of structure, but the inherent complexity is inherent in the problem you are solving, and this complexity cannot be reduced to something simpler.



Being a programmer is not only about generating ideas, and you will not last long in this profession if you do not know how to describe your ideas in code with surgical accuracy. “I’m a little skeptical that systems thinking is the most important in this case, since it’s much easier to outline an idea of ​​a system than to take that idea and turn it into working code,” says Guido van Rossum, creator and retired The Generous Life Dictator of Python ... The web is still JavaScript and Java runs 2.5 billion Android phones, but Python has become the de facto standard in general programming and education.



The one who did the most to make it easier for many people to code their ideas is Guido van Rossum, who gave 30 years of his life to the Python language. Moreover, he did it with unassuming grace and muted humor. The language is named after the grotesque comedy show "Monty Python", not after the Burmese snake. Without further ado, the Python programming language has made it possible to simplify some things in programming, especially for comprehension.



To understand how van Rossum did this, let's take a look at the history of computing and jump into the era of mainframes and machine language. "The mainframe is a million dollar machine, and the combined salaries of all of its programmers are just pennies compared to the cost of the mainframe," says Rossum. Therefore, it is logical that machine time was regarded as a higher priority than human time. "But when dealing with desktop workstations and PCs, I realized that it is high time to change the attitude towards the ratio of human time and machine time." Van Rossum does not consider himself the first to notice this change, but he really emphasized it when designing the Python language.



This simple idea of ​​"machine for man, not man for machine" is the essence of the whole philosophy of the Python language. Specifically, the fact that it is an interpreted language, not a compiled language, implies that the programmer sees the effect of the written code as soon as they write it, without having to recompile it after each change. Today, this practice is very common, but many years ago it was perceived ambiguously, since it seemed certain that the faster the computer, the better. Redefining this belief has had a significant positive effect on programmer productivity.



“There are a whole bunch of common programming problems that are easier to solve in Python,” says van Rossum. - "For those who are not yet a programmer, but only want to become one, the threshold for entering Python is especially low." Indeed, many programming courses are beginning to move away from Java in favor of Python because it is much more understandable for beginners. The reasons behind this transition are complex, with many factors, each of which has eliminated a few rough edges. The essence of philosophy is at the heart of all improvements: everything must have a purpose. When there is no redundant code, it is easier to focus on what you really need to focus on. “In Python, every character you type matters,” says van Rossum.



This conciseness ensures that Python is easy to achieve tangible results, which is why the language finds such widespread use. “It's also important how we introduce Python to novice programmers. You can show a person very small pieces of code that you can work with, almost without understanding the terminology and programming concepts as such, until you understand them, "explains van Rossum," while in the smallest Java program you will find a whole heap of symbols which will seem like ripples to the uninitiated eye. "



With such a calm and simple design of the language, it is easier to understand what is going on in the code. “Python seems incredibly descriptive to me,” says van Rossum. “When I read Python, I definitely perceive its structure as two-level, not as one-level. This is probably because indentation is important in Python, and perhaps because I just like to think visually. "



Of course, visual thinking is not peculiar to him alone. We all think in this way to some extent. But he especially emphasizes the role of the visual component in cognitive activity. “If the text is badly formatted, it can infuriate me. Then the parsing of the text stream gets confused in my head, and in this sense, it really can be argued that I think in Python, ”admits van Rossum. "I'm much better at assimilating code if it's well formatted." Indentation in code is arbitrary, then more information is required to unravel the meaning of the code than if each indentation has a clear purpose, as in Python. Therefore, Python is convenient to work with: you have to digest less information to understand what is happening.



Python is not only readable in terms of typography, but also conceptually. Van Rossum believes that Python is perhaps more accurate than other programming languages ​​for our visual perception of structures represented in code, because "in Python, adherence to structure is mandatory."



Clive Thompson, author of CODERS", Says that" while preparing to write the book, I spoke with a lot of developers who are completely in love with Python. Almost everyone, without exception, said something like "Python is beautiful." They liked readability and found it easy to catch a glimpse of Python code and understand its purpose. This language, devoid of curly braces, with lines arranged like neat shelves, really resembles modern poetry. " They also think Python is fun to write, which is much more important than it might seem at first glance. Thompson writes that "when you get to know a coder, you see in front of you a person whose main daily work is full of endless failures and oppressive frustration."



When respect for the programmer's time is built into a language, it reflects in an interesting way in the language community. There is a social philosophy that stems from Python: the programmer is responsible for his code, knowing that he is writing it for other people. There is an unspoken thesis that van Rossum himself actively promotes in his texts and lectures: spend a little more time and make it a little easier for the person who will read your code in the future. Showing your own respect to your colleagues and showing that you value their time is an ethic that van Rossum quietly promotes around the world. “You write code primarily to communicate with other programmers and to a lesser extent to impose your will on the computer,” he says.

The versatility of the culture surrounding Python has allowed some of the vision that van Rossum had about twenty years ago when he launched the short-lived CP4E (Computer Programming For Everyone) project. “I usually cannot boast of a visionary talent. People ask me what the future holds for Python, and I don’t know. But my most important prophecy, I consider the thesis that the time will come when learning programming will be expedient for everyone. " At that time, personal computers had been around for about 20 years, but most of them were hyped typewriters and calculators. Then van Rossum asked the question: "Isn't it crazy that so many people have computers, but so few people who learn to program?"



Since then, he has been constantly simplifying programming, and this work can easily be traced back to the development of Python, which has now reached version 3.7. You Rossum continues to believe that programming instills generally useful skills, in particular, the ability to solve problems, carefully follow one direction or another and understand the meaning of this direction. But he also found that “there are introductory programming options that are interesting to children, but not everyone; therefore I don't think that programming should be included in the school curriculum as a compulsory subject. "



At the same time, today it is no longer so important for a person to program his computer, since many ready-made programs have appeared, especially on the Internet, and they allow you to intuitively cope with tasks for which solutions previously required programming.



However, there are now more and more people using Python in a variety of disciplines. “One theory prevails today that explains the unexpected success of Python,” says van Rossum, “according to which he was fortunate enough to have a foothold in data science and machine learning, and data science in general. Once you have developed a critical mass of Python skills, it’s easier to work with the same system as your peers and your competitors than to learn new things. ” Moreover, according to van Rossum, although Python began as a common tool for programmers, today it is also a language for amateurs, and, according to van Rossum, it is the best use for Python.



A successful open source software project like Python would be easy for beginners to learn, but also find practical applications in real world problems that more advanced users would need. Just as when working with beginners we strive not to complicate the language so that they can devote all their mental strength to learning the complexities inherent in the development environment, so when working with advanced users, the simplicity of the language comes in handy, since it makes it easier for a person to learn competing abstractions. The desire to make Python implementation as simple as possible is partly due to the fact that when working with this language, it is easy to change opinions, learn, repeat. “Writing a prototype in Python and putting it into production is often not that difficult,” says van Rossum.“And then you can afford to throw away this prototype and implement the same based on what you have already learned. The second version can also be written in Python, but it will be much better than the first. "



The relentless appeal of Python is partly due to the language's optimism and how easy it is to start over. "If you've spent a lot of time writing and debugging code, then you really don't want to throw it away and start over." Drpopbox co-founder and CEO Drew Houston wrote the first prototype of the service in Python on a five-hour bus ride from Boston to New York. “The first Dropbox prototypes were largely scrapped, many times,” says van Rossum.



What can you learn from Python about how to create quality mental tools? Tim Peters, one of the largest contributors to Python, provides some hints on this topic in the aphoristically written “ Zen of Python”, Which explains the principles that guided van Rossum. In the context of this article, the following two are most important: “Simple is better than complex. Complicated is better than overcomplicated. " This is practically a recipe for the brain to prioritize its own functions for efficient energy use.



For van Rossum, the social aspect of thinking and creating tools is equally important. What did he learn from his thirty-year odyssey with Python? “I learned that it was impossible to cope with such a matter alone, and it was a difficult lesson for me. I learned that you don't always achieve the result you were striving for, but perhaps the result is no worse or even better than what you expected. "



All Articles