Sunday, October 15, 2006

The most important thing about Python is that it is Pythonic.

I recently spammed my friends and co-workers with a success story and commented about how Python could be the salvation of a certain project with a particularly gnarled PHP based front end.

I was cautioned by a wise and pragmatistic friend:

Why not suggest Lisp?

Latching on to a single language / platform / religion does not guarantee success or salvation.

I appreciate the good advice, but I don't honestly believe that Python is a magical panacea. In fact I don't want to latch on to Python as a single language or platform. Python has been described as "the ultimate glue language" in that it is well suited to tie various other languages and platforms together. What I do want is to explore Python and convince as many people as I can (who I need or want to work with) that Python is currently the best candidate for the default language to use when implementing solutions to the problems we need to solve.

Lisp is the language which forced me to learn a new way of thinking about representing a problem's solution in code and I am a better programmer for it. It introduced me to the concepts of Functional Programming and non-imperative languages.
  • Imperative Programming describes an algorithm in terms of how a processor will execute it. Processor friendly.
  • Functional Programming describes an algorithm in terms of the mathematical relationship between the problem and the solution. Problem friendly.
  • Declarative Programming describes an algorithm in terms of logical assertions and rules. Human friendly.
Lisp is a very very powerful language. It is probably the most prolific implementation of a Functional language. Learning Lisp also made me realize just how powerful a fully dynamic language could be. I've come to think of Lisp as perhaps the most powerful language.
All languages are equally powerful in the sense of being Turing equivalent, but that's not the sense of the word programmers care about. (No one wants to program a Turing machine.) The kind of power programmers care about may not be formally definable, but one way to explain it would be to say that it refers to features you could only get in the less powerful language by writing an interpreter for the more powerful language in it

--Paul Graham
Ok, so what? Any dynamic language meets this definition power. Perl, Ruby, Python, maybe even PHP (just to list a few of the popular kids). What makes one any more desirable than the others? Religion?

Yes, religion. I'm using a particularly specific definition of religion and I'm using it loosely:
Religion: The collective customs and traditions of a body of people that have formed an organization or an institution to pursue the study of a specific teaching or belief.
Perl has a underlying philosophy: "There's more than one way to do it" (Which Ruby has adopted).

PHP's underlying philosophy is less of a philosophy and more of an excuse:

PHP is not about purity in CS principles or architecture, it is about solving the ugly web problem with an admittedly ugly, but extremely convenient solution.

--Rasmus Lerdorf (the creator of PHP)

The nearest thing Lisp has to a philosophy may be the koan-like description, "The programmable programming language."

Python's underlying philosophy is all about "One obvious way to do it". The Pythonic philosophy.

The Python community ensures that the language represents a collection of a carefully chosen solutions to common problems. Whenever I am about to code in Python there is one question I ask myself (which is the question I was taught to always ask before ever implementing any solution): "Has someone already solved this problem"? I look at the docs for Python's included modules and if I find one I use it. Any problem that can be solved by simply stringing several python modules together can be solved trivially. Solutions like that start to look more and more like Declarative Programming. When i need to take the next step and actually code a solution myself, again, I turn to the community and look for the pythonic way to code the it. I know this will make my code easier to understand for the python programmers who will need to reuse or maintain it later (quite possibly, me!).

Python is a not magical. Python is not an "end-all-be-all" solution. It's simply the "glue" that allows me to mash pre-existing solutions together to form a solution to even larger problems. I've been pretty happy with most Python implementations but that's just a bonus because the implementation is not the language, it's just the interpreter. In turn the language is just a contract between a software developer and a solution. For me, the most important thing about Python is the philosophy. For me Python is the contract between a great philosophy and the community that follows it.

No comments: