Sunday, January 13, 2008

What is so great about Python?

No, I'm not making a statement. I'm asking a question. What is so great about Python? I made some faltering attempts at learning it, mostly through reading the O'Reily book, "Learning Python" and experimenting with some trivial programs.

So, what makes Python so great? Of all the answers I've heard, the most irrelevant and pointless answer seems to be the significance attached to indentation. Apparently, unlike other block-structured languages like C, Python has no delimiter to demarcate the start and end of a block. So, a program that looks like:

if ( x == 0 )
    printf ("This is crazy\n");

would be transformed into:

if ( x == 0 ):
   printf ("This is crazy\n");

Apparently, the founder of Python was so frustrated with the poor indentation that many C programmers use that he decided to make indentation a significant aspect of the language. So, why should I, someone who always cribs about other people's poor indentation styles, have a problem with it?

Well, simply because this is a fascist solution to a simple problem that can be solved by a keystroke or a command (depending on your environment). We don't need a language to force us to do this, in the process causing more problems than it solves. Think for instance, you are looking at a 1000-line Python file, and accidentally you hit a tab or a space. A 'worthless', 'invisible' token like whitespace will now give you logical nightmares!

Any other features that are useful?


Prashanth said...

Oh well, some people use intelligent editors (I use Emacs for instance) so they don't have problems if they accidentally hit a tab or space in a white space region.

And oh btw, comparing C and Python is like comparing oranges and apples. Perhaps a little more researching about the topic would tell you what are the `other' features of python.

Gops said...
This comment has been removed by the author.
Gops said...

How does that work (not having problems if you accidentally hit a space or tab in Emacs)? Don't tell me Emacs prompts you: "Hey, did you mean to type a space here?"

The point I'm making is that your language should not make the logic of your program dependent on subtle things like the number of spaces. Imagine, in trying to solvethisproblemofmenotputtingspaces, you went ahead and said: "this sentence that has a single space" has a different meaning from "this sentence that has a single space ". [it has two]

I'm not comparing C to Python - I just took an example from the language that has mostly become the standard for PL syntax - at least amongst most 'commercial' languages. I believe, as I told you in person earlier, that language comparisons are always apples to oranges comparisons.

I'll still keep the question of other features open to my 'readers'. I wanna get a list of their opinions, not make my own.

That is the point I'm trying to make.

Prashanth said...

You can try out emacs + python-mode at my desk.

The biggest advantage of python IMHO is the interactive interpreter and automatic garbage collection. At the end of the day, the programmer has to choose what functionalities he wants, and choose the language that best provides the cross section of these features.

When I said comparing C and Python is like comparing apples and oranges is because they are both in leagues of their own. Python is a 4th generation Object Oriented (with flavours of functional languages) interpreted language. C on the other hand is much closer to assembly than to Python.

Anonymous said...

Nobody I know likes Python because of its compulsory block-indentation. (I also think hating the language for this is akin to hating C++ for all the angle-braces. One gets over it)

A lot of people (me included) think the functional-programming support is cool.

Gops said...


I don't hate Python - fortunately, I've used too many languages to do that. I only think that a particular feature of Python is fascist. That's all.

Yes, I've heard of other reasons - scripting, libraries, and of course, functional programming - all strong reasons for using Python, but they are also offered by other environments, F# or OCaml, or (shudder) even JavaScript.

You didn't however, counter my point of the significance attached to whitespace. What are your thoughts on that?