Why I love Python (warning: rambling)

KefX keflimarcusx at aol.comNOSPAM
Tue Oct 28 06:12:45 EST 2003


I've been following the group a bit (somewhat loosely; discussions involving
other languages or advanced concepts kind of lose me), and I see all this
negativity (OMG Python's lambda is borken roflol, use teh othar langauge). I as
a relative newcomer to Python pay little heed to the criticism, though. A few
things in Python are counterintuitive, yes, but what language doesn't have such
things? And I feel that one can master the syntax of Python in far less time
than one can for many other language (at least this was true for me). For
little reason other than to take a break from all the trolls, I've decided I'd
write why I love Python. Most of you will already know these things, but for
the other newbies and the outsiders who need to be convinced...;)

I come from mostly a C background. Now, let's get something straight here: I
never had a real job programming, nor have I ever completed any large programs
(however many times I have made large portions of programs). But I've still
written a substantial amount of code in some languages, including testing and
such, and I also have many books. ;) So I still know what I like in a language.

Here are the languages I've learned: BASIC (several variants, including
QBasic), Visual Basic, C, C++, D, Small, Java, Python, Turbo Pascal, Perl,
Assembly (x86, Z80, 6502), and there's always one or three that I forget. I was
tempted to add Delphi, but I didn't really learn much of it that Turbo Pascal
didn't have. I probably will learn LISP or Ruby next. Of course, I know some of
these better than others...I've forgotten much of Perl and Pascal (however some
documentation is probably all I'd need to get up to speed).

I actually learned C as a stepping stone to C++, sort of...eventually I grasped
the OOP concepts and had been writing full-fledged C++ for some years before I
realized that I hate C++. That language is a monster. It looks easier to
understand than it is. Some of the things in my advanced C++ texts give me
nightmares. I'm not saying C++ users are stupid for using C++ or anything like
that -- it's just not for me. I was in AP Computer Science for three years in
high school (because it was so easy, and gave me time at school to code REAL
stuff)...some of the things that they don't teach in the book kind of freak me
out (their teaching of exception-handling was atrocious, for instance). I still
use C++, in fact one of my current projects embeds Python into it, but I don't
have to like it. :) C++ may well be the right language for certain jobs...I try
to stay away from those jobs. ;)

But I grew dissatisfied with C, too, as a general-purpose language because it's
more on the opposite end of the scale. You have to type so much just to do
something simple sometimes. And doing OOP code in C is a hassle. Not doing OOP
code in C sometimes leads to inflexibility...meaning C's not the tool for that
job, unless you have to have it hyper-omega-ultra-fast while still
portable...I'm more of a designer than a programmer. I like being able to think
something and just typing it out. I don't want to do pointer arithmetic, I want
to just implement my ideas.

So I became a Java nut for some time. Java, when it comes down to it, its
taking both C and C++ and fixing anything that is too complex or too low-level
(and then trying to make it portable). But it has some oddities...it wants to
be type-strict, but if you want an abstract container, you have to cast to
object. Huh? It looks to me like in Java, you're doing high-level things using
low-level thinking. Sometimes it's too easy to do what you want...other times
it's near impossible. Again, I'm not bashing any of these languages, I just
don't like them as general-purpose tools.

I was led to try D sometime (http://www.digitalmars.com/d/). I'd always been
interested in it and tried a recent version of the language and compiler. Nope.
Doesn't click for me...it seems as schizophrenic as C++, both in its goals and
in its implementation. I liked it at first, but...nah.

You'll notice that these languages all share a common style of syntax and
semantics. C++ is based on C, and Java is indirectly based on C++, and D is
based on all of the above. I decided I just didn't like the syntax and
semantics, and one day when I needed to write a script to process a text file
and spit out the result in another file, I knew I didn't want to use one of
these languages. I decided to try Python.

I'd already tried to learn Perl by this point. I sort of succeeded. But Perl's
so hairy that if you put it in the forest, people will have their definitive
proof of the existence of the sasquatch. I can't read Perl code even if I wrote
it. So while I respect it, as I respect most languages, as a specific-purpose
language, I didn't really want to bother with it for this task, as I wanted to
try a general-purpose language, other than the "general-purpose" languages I
already knew. So Python it is.

Wow.

This is the language I've always wanted to see. Bad indentation is nearly
non-existent (if you've seen an AP Computer Science classroom and took a look
at the C++/Java code on the students' monitors, you WILL shriek with horror at
half of it). The language and the library complement each other well, and if
you can't do it simply with the language, you probably can with the (massive)
library. Types are rendered almost unimportant. Python, to put it simply, asks
the programmer that crucial question: "What is the ESSENCE of the problem?"
Rarely do I find myself wrestling with the language's syntax. I feel I've
mostly mastered the syntax and semantics and I needed little more than the
Reference Manual and the Python Tutorial!

I personally feel that the performance worries that put C and C++ as the
industry standard (with Java not far behind because "it looks like C++ and it's
not THAT slow") are becoming increasingly unwarranted. It's kind of ironic for
me to say this as I have a current program I'm working on where Python is
certainly running too slow for me (though I'm working on that). But that's a
special case, in this case, digital signal processing.

Of course, I still have my own (minor) issues with Python. The way name binding
works is kind of odd to me, but it does make sense to me more often than not,
and I'm getting used to it quickly, unlike some trolls^H^H^H^H^H^Hpeople I
know. The immutability of strings is also kind of strange, but I understand why
it's done...namely so people don't accidentally do this:

foo = 'this is a string'
bar = foo
foo[:4] = 'that'
print bar  # Prints 'that is a string'!

And instead the interpreter provides a helpful traceback on line 3 saying in
essence 'You can't do that'. (Then people who don't understand why will then
rail about it on the newsgroup instead of discovering that foo = 'that' +
foo[4:] produces the intended result...) I don't think there's anything
preventing anybody from making a 'mutable string' class, though, especially
with how we can inherit from basic types, though I wouldn't be sure of the
wiseness of doing that. Wait. Hold on a minute.

[checks to make sure standard library has no mutable string class...crap! There
is: UserString.MutableString, though it's semi-deprecated. :)]

Yup. That library does have everything. ;) Anyway, to get back to what I was
saying, Python has some oddities...but hey, what language doesn't?...and these
oddities are a lot easier for me to put up with than the ones I've found in
other languages.

I was going to say more, but I've rambled enough for one night/morning/whatever
it is now...time to get back to actually coding, and then sleeping. :) I hope I
didn't make myself, or anybody else, look too foolish.

- Kef





More information about the Python-list mailing list