Friday, May 22, 2009

A picture is worth a thousand words



Just something I came by in my travels 'round the net. After running with some other languages in the past, Python certainly makes me feel like that, unless its the crack that's talking...

Monday, May 11, 2009

Design Patterns in Python

Interesting talk on the merits of Python when it comes to software patterns. I think it would be an interesting exercise to grab one of the popular pattern books and translate the patterns to concrete Python examples and publish that as a programmer's resource. I'd do it but I'm too busy writing this blog.... :)


Sunday, May 10, 2009

Why Python?

A facebook friend, an aspiring programmer was asking me why I think Python is so great. I thought this would be a great way to begin this blog. This would enable me to enumerate what the salient features were for me that make it such a joy to work with.

I'm a code junkie, been that way since I first wrote my first line of code in BASIC, I was always looking for some other language that would address the deficiencies of the previous. I've moved from BASIC, COBOL, Pascal, Assembler, C. Worked with database packages/languages like DBaseV, Clipper, SQLplus. I had to bend my mind from procedural to object-oriented programming (which caused all of us to talk about the objects were were crafting in the first person) which catapulted me into C++ and Windows programming.

Having navigated the previous decade of programming languages and paradigms, which had been a tumultuous time, I'm glad to have discovered the safe harbor of Python. Its great because...and Mark Lutz says it so much better in his book "O'Reilly's Programming Python" and I'll try to paraphrase.

The immediacy of code

Python is an interpreted language. Programs in python consist of modules that are loaded at runtime and their objects executed, because of this one can edit the code while the program is running and have the newly edited code executed when the module is reloaded. Development time decreases dramatically.

You can have a program rewrite its source code, reload and execute it all while its running without skipping a beat, great for genetic programming or having a daemon upgrade itself without restarting it. Other benefits I've found is being able to develop and debug GUI based applications quicker since you don't have to restart the application everytime you change any code. You can edit the code, save the module file and click on the button in your GUI app that will reload the module and run the code. The time savings are enormous and I don't get distracted by waiting for a GUI application to load up.

Pseudocode

Python is a high level language, alot of the low level details are handled by the language itself allowing a simpler language that handles details like dynamic type casting, memory managment and garbage collection. Because all these details are missing we're left with the actual problem that is to be solved.
Reading python programs is much simpler since we're not bogged down with details about memory managment and type casting (in C/C++ they are the major culprits for bugs). Python programs read like pseudo code and makes writing algorithms easier since it allows you to concentrate on the problem at hand and delegate the low level stuff to python.
I've read code that I wrote a year ago (when I was just starting out ) and I was still able to understand it, I wouldn't have been able to do that with C.

Object Oriented

Python allows you to write object oriented code since the language itself is based on objects. All the basic elements are present such as single and multiple inheritance, all that good UML stuff

Hybrid Application development

Python can support calling functions in libraries from other 3rd party languages. All you have to do is create a special python file that operates as a map between the native function and the python function, this lookup is provided to the python interpreter and the call to the library function is made and returned to the python interpreter. This feature allows you to leverage code that has already been written and putting a simpler interface via python. Depending on the application that you're running, the degree of hybridization is determined by performance needs and how easy it is to integrate the 3rd party components.

All these reasons and more have made me a fan of this awesome language and I continue using it with the same enthusiasm from the beginning, so join me as we ride the python and learn something new.