Friday, December 4, 2015

Why I Like Python

Python is a simple, easy-to-learn language that is in widespread use, especially in the open source community.  In most Linux distributions(Fedora, CentOS/RHEL, Ubunu/Debian) many system tools are written in Python and it is used for GUI configuration tools, for example with Python+GTK.  It is largely replacing Perl and other languages for scripting tasks.

The language syntax is simple and easy to learn.  The simple syntax encourages best programming practices.  Variables are defined when they are used and the data types are easy to understand.  As a result Python is being taught as a first computer language in middle schools through colleges.

Python is mainly an imperative programming language supporting both functional programming like C, and object oriented capabilities like C++/Java (python classes).  However, Python has some features that allow it to be used as a declarative programming/functional programming language such as its lambda function.

The language has many features that make it ideal for solving fairly complex problems:
  • forced structure with indents, optional “;”, and no “{}” for loops/procedures
  • quick startup and runs fast (slower than compiled languages, however)
  • interpreted, but modules are byte-compiled, which improves speed
  • widely used in open source projects 
  • supports multiple graphical extensions such as GTK for development of GUIs
  • included in most Linux distributions
  • very extensive set of standard modules
  • many add-on modules from many sources
  • numeric python and scipy are great for scientific and engineering tasks/data analysis
Python is a great language for many things, but not all.  For example since it is interpreted, it is not as fast as C/C++, nor as suitable for hard-realtime (for example due to garbage collection -- a problem that Java also has).

Most Python code is interpreted and runs in the C-based Python interpreter (cPython).  However, there jPython allows Python to run in the Java virtual machine and there is even a micropython that allows a subset of Python to run on bare metal in a microcontroller:

Perl is great for small, quick scripts, but Python is better for larger, complex scripts, and for jobs that would have been implemented in C/C++/Java a few years ago, such as signal processing or analysis of large data sets.  Some functionality such as regular expressions and system calls are easier in Perl. However, Python is much cleaner, resulting in code that is easier to understand, share, and reuse.  If you share it or must maintain it, Python is the preferred language.

Python is also challenging Matlab/Octave for engineering tasks and signal processing.  Numeric Python (Nympy), Scientific Python, Astro Python, and Matplotlib ( are several of the projects extending Python for scientific processing.  Many of the features that can be done in Matlab/Octave can now be done easier in Python, and since Python is a more mainstream language, they can be understood by a wider audience.

Some useful links:

No comments:

Post a Comment