Friday, May 14, 2010

The Python Experience

Today I will write an introductory post on Python, few days back a student said to me, "Python must be hard" and she is the main reason why I came up with this post.

In one phrase I would say that Python is the best of both worlds because it is capable of delivering the power of traditional compiled languages like C, C++ and the ease of use and simplicity of scripting, interpreted languages like Perl, Tcl. In the world of Python imagination literally becomes the limit for the programmer.

Few people know that Python is used for major tasks by companies like Google, Yahoo!, NASA, Red Hat, Pixar, Disney and Dreamworks. In fact today what we see as Yahoo! mail was the Rocketmail Web-based email service and it was designed in Python. Today many universities are planning to use Python to teach introduction to programming so that students can focus on problem-solving skills instead of being bogged down by the difficulty of the language and some including MIT have even started to do so.

So here goes for the students back in Pakistan the basic features of Python which make it so appealing and powerful:

  • Of course it is a high-level language, its beauty lies in its higher-level data structures that reduce the development time marginally.
  • Python has support for object-oriented programming, in fact it is an object-oriented language all the way down to its core.
  • With python the code is compact and that's also the beauty of it. Python is often compared to batch or Unix shell scripting languages. But with them there is little code-reusability and you are confined to small projects with shell scripts. In fact, even small projects may lead to large and unwieldy scripts. Not so with Python, where you can grow your code from project to project, add other new or existing Python elements, and reuse code at your whim.
  • Python's portability is also what makes it the most widely used programming language today, it can be found on a variety of systems. Python is written in C and due to C's portability Python is available on practically every platform that has an ANSI C compiler.
  • Python is extremely easy to learn and students can grasp it very quickly so I would certainly recommend to many students reading this post and if you need any sort of help feel free to contact me.
  • Python's code is very easy to read so much so that even a reader who has not ever seen a single line of Python will begin to understand and read the code instantaneously.
  • Python code is extremely easy to maintain and if you review a piece of code you wrote some months back you will be able to grasp it in no time.
  • Python is robust to errors. Python provides "safe and sane" exits on errors and when your Python crashes due to errors, the interpreter dumps out a "stack trace" full of useful information such as why your program crashed and where in the code (file name, line number, function call, etc.) the error took place. These errors are known as exceptions. Python even gives you the ability to monitor for errors and take an evasive course of action if such an error does occur during runtime. These exception handlers can take steps such as defusing the problem, redirecting program flow, perform cleanup or maintenance measures, shutting down the application gracefully, or just ignoring it. In any case, the debugging part of the development cycle is reduced considerably.
  • Now comes the one great thing I simply love about Python: numerous external libraries have already been developed for Python, so whatever your application is, someone may have traveled down that road before. All you need to do is "plug-and-play". There are Python modules and packages that can do practically anything from natural language processing in NLTK to scientific computing and everything you can imagine. In Python if you cannot find what you need chances are high that there is a third-party module or package that can do the job.
  • Python has its own memory manager, the thing that makes C and C++ extremely burdensome is that memory management is the responsibility of developer: the programmer has to take care of dirty tasks of memory management no matter what but with Python this headache is gone.
  • Python is classified as an interpreted language. However traditionally purely interpreted languages are almost always slower than compiled languages because execution does not take place in a system's native binary language. But like Java in reality Python is byte-compiled i.e. results in an intermediate form closer to machine language. This improves Python's performance while allowing it to retain the advantages of interpreted languages.
So dear students I would certainly recommend all of you to do give it a go at Python as in the long run it will really benefit you.