Saturday, December 19, 2009

Python, The Good And The Bad

First off, im a bit of an obsessive programmer. I have been programming since like 7th grade or so. It began as just web design, and eventually became a well developed underlying understanding of many types of programming. The languages I have come to know include (in no particular order): Python, PHP, C++, Bash Scripting, C#, Java, ASP.NET, Javascript, CSS, and (X)HTML. Of these, python is the last one I learned. I only really put a focus on it within the last half-year. Since I have come to use it a lot, I have come to love the language more than others. It may not be as fast as a compiled language, but it is way more simplistic and powerful, yet easy to learn and use, than any other language I have come across.

Now for some of the pro's:
  • The language is entirely indentation dependent. Rather than using curly-braces for grouping and scope, it just uses depth of indentation. Aside from the lack of extra lines used just for curly-braces, it teaches the programmer the importance of writing clean, readable code.
  • It is module based. Rather than having everything at a global scope, as in PHP. You can just import what you need to use, and no more.
  • It allows using libraries written in other languages, such as wxWidgets and GStreamer. This allows you to write fast compiled code, then use the compiled code directly, rather than writing code in just pure python.
  • Everything's an object. Every class, string, list, function, etc is an object. They all have attributes and methods. They can all be assigned to a variable or passed as an argument.
  • Documentation. I have found an abundance of documentation for doing what I need to, even if in the __doc__ attribute provided with every object.
  • Flexibility. It is simple to make a program that will work on multiple platforms without much work.
  • And on, and on, and on ...
Ok, now lets look at the downsides:
  • Performance. Python is certainly not a compiled language. As such, it doesn't run as fast as a compiled language. C/C++ programs are compiled, so they run as fast as the computer allows (based, of course, on the quality of code written). Python is an interpreted language, so it doesn't have that low-level benefit.

Aside from the inherent performance penalty, python is an amazing, powerful, simple language. I learned it using, obviously, google (the best search engine ever), ipython (an interactive, introspecting, well-designed python shell), and a lot of experimentation. Recently I took on the moderately sized project of writing a gstreamer backed command-line media player, with audioscrobbler support for last.fm song tracking, and dbus support for gnome mediakey control. I used python because I couldn't get it to work how I wanted in other languages. Also, it took days to write the base code, not weeks.

Now, some resources for learning python:

Google - Best search engine ever.
The Python Website - Good place to find extensive core documentation.
Dive Into Python - Perhaps the best step-by-step, noob-to-pro documentation ever written.
IPython - Well written interactive, introspecting python shell.
EXPERIMENTATION - The best way to learn anything.

I have come to highly advocate this language and recommend it to anyone, whether just starting into the world of programming, or just wanting to learn a new language. Good luck!

No comments:

Post a Comment