Wednesday, August 1, 2007

(Object Oriented) Python Rant

Python is the way of the future...like Zeppelins and Autogyros. It's a lot more natural programming in Python than it is in Perl, at least for Object Oriented Programming. (Note that there is an interesting series called the Python Papers that is a good read!)

When I first learned it, I hated it because it wasn't like C/C++/D/Java at all! However, I gave it high marks for having the lambda anonymous functions. It made me reminisce about the bad old days of LISP and SCHEME and The Structure and Interpretation of Programming.

Now, my tune has changed completely since I'm working on an operating system (Brainix). I recognize the value of having scripts, despite the fact that Brainix is not mature enough to run a simple shell. It's the benefit of platform independence at the cost of performance.

The problem is that there are no good scripting languages! Perl is esoteric as death, and BASH is not all that better...don't get me wrong, BASH is fabulous as a shell but terrible as a scripting language. Python is perhaps the best scripting language out there, and that's not saying all that much.

One particular problem that I have is, for perl I can do things like:

@files = `ls`;
for $file in @files
{
#do stuff!
}
However, for Python, having this neat scripting feature is changed! In the immortal words of "Grandpa" Simpson "I was with it once...then it changed into something horrible and scary." After a bit of study, I figured out that there is an OS module where I can use the os.system() method to invoke shell commands. Now I could write something like:

foreach file in os.command("ls"):
# do stuff translated into python!
Perhaps a more disturbing difference for my inner C/C++/D/Java programmer is the lack of curly brackets. I got over this by using Python in a more functional manner that would make John Armstrong proud.

Finally I fought my fears and started programming in an object oriented manner. Object oriented programming is the way of my people! But this sort of object orientedness seemed odd. The self pointer (I assume, I thought it to be a python parallel to the this pointer at first) is the first argument in every method, which was bizarre. It reminded me of Phil's Object Oriented ANSI C.

Perhaps what the open source movement needs is a good shell that's also a good scripting language...one that's open source, object oriented, and is an affront to the Windoze PowerShell. BeanShell is a possibility, but I think there is hope for python yet.

Well, this isn't much of a first post, but that's all I have to rant about so far about Python.

2 comments:

Anonymous said...

Hi,

Editor-In-Chief of "The Python Papers" here ... I saw your post on my RSS feeds and came to have a look. I was wondering if you would be happy for me to reproduce your blog post in our next issue?

If that is okay with you, let me know by email at tleeuwenburg@gmail.com. I'll check back here also, but email would be preferred.

All the best,
-Tennessee

Anonymous said...

Well said.