📜 ⬆️ ⬇️

Python shaping - Guido van Rossum (part 2)

image This is a continuation of an article from the official blog of the author of our favorite language. Therefore, the story is on behalf of Guido van Rossum himself. The first part is here .

Introduction and Overview



Introduction.

Python is now one of the most popular non-compiled programming languages, along with Perl, Tcl, PHP and Ruby. Although it is most often viewed as a "scripting language", in fact it is a fully-fledged programming language suitable for solving most standard tasks and occupying the same level with Lisp or Smalltalk (as well as with many others). Currently, Python is used for virtually everything - from one-time unpretentious scripts to large extensible web servers running 24 hours seven days a week. It is used to develop GUI applications and databases, client-server web applications and testing. Python is used by scientists who write applications for the world's fastest supercomputers, and by children who learn to program for the first time.
In my blog, I want to shed light on the history of Python. In particular, how it was developed, what influenced its structure, mistakes made, lessons learned and plans for the future development of the language.
')
Acknowledgments: I am indebted to Dave Beazley for many good words on this blog (for a story about the appearance of this blog, welcome to my other blog ).

Flight over the python's nest.

When users first encounter Python, they are very surprised that the code written on it looks, at least outwardly, very similar to code written in other traditional programming languages, such as C or Pascal. Not surprisingly, the Python syntax grew straight out of C. For example, many of the keywords (if, else, while, for, etc.) coincide in meaning with those of C, identifiers get their name according to similar rules, and Most standard python operators have "sishnye" counterparts. Of course, Python is far from C, and, for example, one of the main differences can be called the use of indentation by python instead of curly braces to group statements. For example, here is an example of code written in C:
if (a <b) {
max = b;
} else {
max = a;
}

Python, in this expression, does without parentheses at all (as well as without semicolons) and uses the following structure:
if a <b:
max = b
else:
max = a

Another area in which Python is very different from C-shaped languages ​​can be called its dynamism. In C, variables must be correctly declared, and they must be assigned a special type, for example, int or double. This information is used when compiling a program to check that the program allocates memory correctly for variable values. In turn, in Python, variables are simply names that refer to specific objects. They do not need to be declared before assigning them values, and they can even change the type in the middle of the program. Like other dynamic languages, all input checks are performed by the interpreter in real time instead of using an additional compilation step.

The simplest built-in Python data types include boolean types, numbers (integers, arbitrary precision numbers, and real and complex floating-point numbers) and strings (8-bit and Unicode). All this is immutable types, which means that the values ​​represented by objects cannot be changed after their creation. The built-in data union types are called tuples (immutable arrays), lists (resizable arrays), and dictionaries (hash tables).

For organizing program files, Python includes support for packages (group of modules and / or smaller packages), modules (additional code grouped into one file), classes, methods, and functions. For creating branches and loops, there are if / else, while, as well as high-level operators for looping any “iterable” objects. Python uses exceptions to control errors. The raise statement raises an exception, and the try / except / finally statements define its identifier. Built-in operators lead to exceptions for errors in their description or use.

In Python, all objects that you can give your own name for are called “first class objects”. This means that functions, classes, methods, modules, and all other named objects can be freely viewed, explored, and placed in various data structures (such as lists or dictionaries) in real time. In addition, speaking of objects, it is worth mentioning that Python also has full support for object-oriented programming, including custom data types and classes, real-time inheritance and method binding.

Python has a fairly extensive standard library, which is one of the reasons for its high popularity. This library includes more than a hundred modules and is being updated all the time. Some of these modules include regular expression search, standard math functions, streams, operating system interfaces, network components, modules for working with standard Internet protocols (HTTP, FTP, SMTP, etc.) and email, processing XML, HTML parsing and GUI application development components (Tcl / Tk).

In addition, I can say that there is excellent support for third-party modules and packages, most of which are also available in open source. There are web frameworks (too many to list!), More GUI tools, high-quality math libraries (including “wrappers” to many popular Fortran libraries), interfaces to interact with databases (Oracle, MySQL and others), SWIG (allows connecting C ++ libraries as standard python modules) and much, much more.

The main attraction of Python (and, in the same way, other non-compiled languages) is that seemingly confusing tasks can often be solved with literally meager amounts of code. As an example, a simple Python script that retrieves a web page, parses it for the presence of URL links and displays the first 10 of them.
import re
import urllib

regex = re.compile (r'href = "([^"] +) "')

def matcher (url, max = 10):
“Print the first several URL references in a given url.”
data = urllib.urlopen (url) .read ()
hits = regex.findall (data)
for hit in hits [: max]:
print urllib.basejoin (url, hit)

matcher (" python.org ")

This program can be easily converted into a web scanner, and even Scott Hassan told me that he wrote the first Google web scanner in Python. Currently, Google uses millions of lines of Python code to regulate many aspects of its operations, from automation to issuing control (I’ll make a reservation: I’m also currently working at Google).

If you raise the curtain a little more, then we learn that the Python code usually takes effect with the help of the bytecodes compiler and interpreter. Compilation takes place implicitly at the time of loading modules, but some language primitives require access to the compiler in real time. Although the de facto basis of the python structure is written in C and works on any existing hard or soft platform, many other varieties have also found their followers. Jython, for example, is a version that runs under a JVM (Java virtual machine) and has fairly tight integration with Java. IronPython is a version for the Microsoft .NET platform, which also has tight integration with languages ​​that work under .NET. PyPy is an optimized Python compiler / interpreter written on it (it is still at the stage of a research project implemented under EU funding). There is also Stackless Python, a variant of a C-like structure designed to reduce C-stack dependency for function / method calls, for easier work with subroutines, branches, and micro-threads.

Guido van rossum

Source: https://habr.com/ru/post/49564/


All Articles