Why PYTHON?

Why PYTHON?
Python vs C: overhead and variation between different executions of the code.

As I have already mentioned in earlier posts, my project is Timeline Profiling and Visualisation with Python; so I am actually using too much Python. But why should someone else bother learning Python?

Well,there are several reasons!

First of all, when I first started learning Python I realized that it’s actually quite easy. There are no type declarations and the dynamic typing surely comes in handy. In Python you can have modules, classes, functions and everything is handled as an object; that means that you can have a function as a parameter in another function or module !You can also find more interesting properties like exception handling, static scoping, indentation for block structures and operator overloading.

Writing simple Python programs is very easy. Let’s take the always-fun-to-see example of Hello World!

print 'Hello World!'

That’s all. Really, that’s all! You can find a lot of easy to practice examples and of course too many tutorials all over the Internet.[1]

Because it’s that easy!! Source: http://xkcd.com/353/

As you can see, the code is extremely readable. That mean that we can significantly improve our program’s maintenance. Also the development time is quite low;you can actually see that the Python code is 2-10x shorter than an equivalent C, C++ or Java code. Of course, I have to mention that one of the greatest things about Python is it’s interface with other languages; I have already mentioned on an earlier post about Cython which is actually Python with C and is actually what I am using for my implementation.

What also amazed me about Python is the fact that it can provide a balance of High level and Low level Programming.Yes,I will admit that most of the times you sacrifice code speed for programming speed.But actually that depends on the work you need to be done.Let’s check this with a specific example from my project.

In this example we are going to have two simple functions: 

  • inner() which just contains a counter 
  • outer() which calls the inner() in a for loop

So,what I did is to write this example in both languages;Python and C. After adding some simple MPI code,I ended up with two simple example-codes just so I can show the overhead that python actually adds.

Python vs C: overhead and variation between different executions of the code.

Python vs C: overhead and variation between different executions of the code.

Let me explain what this graph is about. I executed the code 15 times at 15 different points parallelizing it every time in 4 threads. The variation of the measurements was expected since the machine used would also have other jobs running on the background .We can see that Python is adding an overhead of about 100 (the C version is about 100x faster than the Python) . For further information about the graph you can check the details.[2]

Python is really all around;it’s used for web scripting,steering scientific application,XML processing, database applications,GUI applications etc.Who Uses It? Well,Yahoo! does ( CGI in Yahoo!mail), RedHat (Linux installation tools) and the most of Ubuntu configurations utilities are pythonic. [3]

PS:Trying to find material for this post I found a nice blog,if anyone interested in Python.

[1]: You can try several just to see which one suits you best;the ones that I liked most are these:

[2]:

Variation Sheet

Variation Sheet

[3]: Check the success stories for more information.

Tagged with: , , , ,
One comment on “Why PYTHON?
  1. Umut Karcı says:

    I believe that for time important jobs, C/C++ may be good just like Apache http server or most of posix core applications. But for a diagram drawing software C++ is extremely time consuming and the speed effect is so small that a normal person can’t even figure. I use Dia, it uses Python and have python console.

    I use python in django to write web applications, I use python for reading data from serial port and with pyqt I print them on screen. I use python and smbus to read data from a I2C circuit and print them with pyqt. I use python for creating basic login applications. I use python for scripting. I use python almost everywhere. I learned it as my third language (Basic, Bash, Python) now I’m learning C as my first compiled language, it’s nice but I miss REPL function all the time.

Leave a Reply to Umut Karcı Cancel reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.