4
|
Chapter 1: Introduction to Python
Python is simple, but not simplistic. It adheres to the idea that if a language
behaves a certain way in some contexts, it should ideally work similarly in all
contexts. Python also follows the principle that a language should not have
“convenient” shortcuts, special cases, ad hoc exceptions, overly subtle distinc-
tions, or mysterious and tricky under-the-covers optimizations. A good language,
like any other designed artifact, must balance such general principles with taste,
common sense, and a high degree of practicality.
Python is a general-purpose programming language, so Python’s traits are useful
in just about any area of software development. There is no area where Python
cannot be part of an optimal solution. “Part” is an important word here; while
many developers find that Python fills all of their needs, Python does not have to
stand alone. Python programs can easily cooperate with a variety of other soft-
ware components, making it an ideal language for gluing together components
written in other languages.
Python is a very-high-level language (VHLL). This means that Python uses a
higher level of abstraction, conceptually farther from the underlying machine,
than do classic compiled languages such as C, C++, and Fortran, which are tradi-
tionally called high-level languages. Python is also simpler, faster to process, and
more regular than classic high-level languages. This affords high programmer
productivity and makes Python an attractive development tool. Good compilers
for classic compiled languages can often generate binary machine code that runs
much faster than Python code. However, in most cases, the performance of
Python-coded applications proves sufficient. When it doesn’t, you can apply the
optimization techniques covered in “Optimization” on page 474 to enhance your
program’s performance while keeping the benefits of high programming
productivity.
Newer languages such as Java and C# are slightly higher-level (farther from the
machine) than classic ones such as C and Fortran, and share some characteristics
of classic languages (such as the need to use declarations) as well as some of
VHLLs like Python (such as the use of portable bytecode as the compilation target
in typical implementations, and garbage collection to relieve programmers from
the need to manage memory). If you find you are more productive with Java or
C# than with C or Fortran, try Python (possibly in the Jython or IronPython
implementations, covered in “Python Implementations” on page 5) and become
even more productive.
In terms of language level, Python is comparable to other powerful VHLLs like
Perl or Ruby. The advantages of simplicity and regularity, however, remain on
Python’s side.
Python is an object-oriented programming language, but it lets you develop code
using both object-oriented and traditional procedural styles, and a touch of the
functional programming style, too, mixing and matching as your application
requires. Python’s object-oriented features are like those of C++, although they
are much simpler to use.
www.it-ebooks.info