in Search
Welcome to Neopoleon - Sign in | Join | Help
Navigation: Home | Forums | Galleries

Python Love

I went out to lunch with a couple of awesome local nerds yesterday. I was about twenty minutes late, but Stuart and Jason didn’t seem to care. I’m guessing that they got all their trash talking done before I showed up.

The conversation was all over the place. I had chugged my late-morning caffeine before arriving, and it was just hitting peak plasma levels when I arrived at the restaurant.

One thing we talked about was Python. I had a little love affair with the language a couple years ago, but didn’t ever do anything with it. I was just curious to know what all the Python hoopla was about. After finding out, I went back to my love.

Something’s going on, though, in the .NET camp. While I don’t have a lot of links to support it, I’ve noticed a growing interest in Python among my friends and acquaintances.

Jason has his bit here, and Sam has made Python a priority for 2005.

When I first looked at Python, my reaction was, “Thank heavens there’s a ‘P’ language that doesn’t mix the flexibility of Silly Putty with the arcaneness of C and the joy of trying to suck a watermelon through a crazy straw.” I hate Perl. ‘Nuff said. Python is often mentioned in Perl conversations, and I think it’s good for the world to know there’s an alternative, even if it isn’t trying to tackle the same problems as Perl. I just figure that, the more people off of Perl, the better. It’s like trying to get drugged teenagers off the street.

When I looked a bit deeper, I was less excited. Python feels like a “fun” language, but it falls short for me in a few areas. Since it’s relatively new, and since it’s a rather modern creation, I couldn’t figure out why parts of it stank.

[Note: The following is based on two year old memories, and could be inaccurate, but I know that it’s at least mostly right.]

First, if you haven’t done anything with Python, then here’s something very important for you to know: Versions of Python prior to 2.0 were a lot like pre-.NET VB in that they mixed a procedural style with OO. When coding with a 1.x Python, it’s easy for it to feel like VBScript. Your world is built around functions that are coming from who-knows-where. It wouldn’t have surprised me to have come across Instr(), Chr(), or Asc(). I hated it.

Python 2.x changes this by providing an OO framework for some operations. Instead of working with a string primitive and then coding against those strings using functions, you have a string object with all the associated conveniences. I… liked it.

I didn’t love it.

I would have respected a choice to have ditched all 1.x hacks, but instead they were carried over to 2.x, so now we had the choice of doing things procedurally or Object Orientedally (yeah – I made that word up – bite me).

What a bloody mess! Let’s see… Do I want to work with functions on my strings, or do I want to work with members of the string object? I hate that kind of crap. Choice and flexibility in expression are “feel good” features, but I tend to think that having a bajillion ways to do the same thing really screws a language over.

Then, there was this irritating business of the constructor. Who’s idea was it to call it “__init__”? What’s with all the underscores in the language? Here we (the coders of the universe) had a chance to clean things up, but instead we got this confusing syntax that feels like a last minute kludge.

Not that I think Python is the only modern language that should be picked on for strange constructors. I happen to think that VB.NET has it right: New(). It makes so much god damned sense. C# is the language I code in for pleasure, but having to have constructors whose names match the class name doesn’t strike me as being necessary, except perhaps to make C# coders feel that their language is somehow more technical than other, equally suitable .NET languages. Most C# coders I know are coding without 3rd party refactoring tools, and I can imagine that they’re often hesitant to refactor just because of the sheer volume of work sitting ahead of them. Not having to rename all their constructors each time they change a class name would allow them more flexibility to go back and make changes later, and New() is a fine solution to the problem.

But I digress. Switching back to Python.

After flipping out about the procedural/OO mix, and then getting all tight in the pants about constructor names, my cheeks burned with anger and frustration a third time when I realized I had to include self in every single bloody method signature’s parameter list.

If self needs to be listed, then why do we have to define it? Why can’t it just be done automatically?

You might think I’m bitching about unimportant issues here, but coding is one place where very small differences can make or break your day since so many tasks are repetitive. Sure, having to add self to a parameter list once isn’t any big deal, but three-hundred methods later, when the ink is worn off the S, E, L, and F keys, you might be thinking differently about it.

Now, to end this thing on a positive note, I’ll say this: I love the interactive environment of Python, and I love that it forces coders to indent. I think that Python makes a lot of sense as an embeddable scripting language for larger applications, and I think that, with a few modifications, it could be the best teaching language ever created.

And now I really have to shut up. My instinct is to go off about other features, but I really want this to finish positively.

Which is hard.

Because I kind of think Python sucks and is as overrated as OS X and Pink Floyd.

Published Thursday, March 03, 2005 11:45 PM by Rory

Filed Under:

Comments

 

Ron Green said:

Oh no. Don't you dare disrespect Pink floyd.
March 4, 2005 1:13 AM
 

Andy said:

Python = Meh.

For me it's just sort of there. If I had to choose between it and Perl I'd take Python but other than that I don't really like or dislike it. It wouldn't be my first choice and it wouldn't be my last choice either.
March 4, 2005 1:55 AM
 

Kris said:

Talk all the shit you will about Python, but when you diss Pink Floyd you diss yourself. Come on now, Rory.
March 4, 2005 2:09 AM
 

Rory said:

Before everybody gets all upset about the Pink Floyd comment, I want to explain my position.

Basically, I think Pink Floyd effing *SUCKS*.

OK - now you can continue with the upset-getting...
March 4, 2005 2:27 AM
 

George said:

Rory,

"Basically, I think Pink Flamingos effing *SUCK"”

I agree, I also think they suck. Thank you for being brave enough to say what the rest of the world was too timid to say about those pink effers.

Now I have to go figure out what Python is since apparently all your friends think it is cool...

It's so hard to keep up with all these fads!!!
March 4, 2005 2:47 AM
 

Scott said:

See, I haven't jumped completely on the Python bandwagon yet. I wanted to learn another language for shits and giggles and I was looking at Python and Ruby. My decision was helped along when Don Box said if he was teaching programming to his kids he'd use Ruby because it was "pretty damn close to perfect". I'm not one of those people that blindly follows whatever people with more experience than me says is "cool". but "Perfect" gets my attention.

"For a super-pragmatic language, it's pretty damn close to perfect.  It would be my first choice if I wanted my kids to learn to program as opposed to learning about math and logic."
http://pluralsight.com/blogs/dbox/archive/2005/02/26/6181.aspx

So I started writing a blog application in Ruby. Why a blog, well the requirements are pretty well defined.
http://www.lazycoder.com/weblog/archives/2005/02/25/new-adventures-in-ruby-part-two/

It doesn't have a lot of the issues that you mention in Python. It's constructor method is called "initialize" which is pretty damn close to "New" as being a perfect constructor name to me. What got me was the way you define getters and setters for properties in Ruby.

attr_reader :name, :author, :entries
attr_writer :entries

I'm not even sure if I'm writing Ruby the way that it's "supposed" to be written but it seems pretty cool so far. I saw a code sample that created a SOAP server in about ten lines.
http://www.rubycookbook.org/cookbook/view/main/SOAP_easy_server_client


March 4, 2005 3:38 AM
 

Jason Olson said:

Okay, time for me to defend myself :). I just want it known that I don't have the kind of "love" for Python where I'm going to go out and blow all the Python dongs that I can find on every street corner. There are certain "aspects" of the language that I absolutely love, especially from a unit testing point of view. The fact that class definitions are first class objects themselves allows you to do some seriously cool reflection-type stuff that isn't really possible in .NET unless you use context-bound objects (whose use comes along with a price).

For the most part, I agreed with all the complaints Rory had about the language at lunch. The object-oriented support for Python you can definitely tell is a hack. And honestly, about the reflection-type stuff I was talking before, I don't see many practicle uses for outside of unit testing (of course, I think this is because of my vast lack of true knowledge dealing with the platform).

With 2.4, there have been some pretty cool new features added to Python. But let's make this clear: at the end of the day, I still whip up Visual Studio .NET and write a program in C#. I'm not saying that won't change though :).
March 4, 2005 3:40 AM
 

Jason Olson said:

One more thing, the primary reason I decided to learn Python is that I wanted to learn a dynamically-typed language since I didn't have any experience with dynamically-typed languages. And considering that I have coworkers that use Python, and that Python has quite a growing community, the decision seemed pretty natural.

Okay, you may go on bashing Rory about not liking Pink Floyd. But to make that issue clear also, I respect what they did for music, but I prefer not to listen to any of the "contributions" they made (well, not many of them at least).
March 4, 2005 3:42 AM
 

Ron Green said:

Ok, if you want to be that way about it, people who draw cartoons and put them on their weblog *SUCK*.
March 4, 2005 4:35 AM
 

Aaron said:

OS X overrated?! OS X is about as overrated as the "I'm feeling lucky" button on the Google homepage. Please. The power of UNIX, the flexibility of UNIX and the stability of UNIX. OS X ROX!
March 4, 2005 4:45 AM
 

Ian said:

We use Python as an embedded scripting language and it IS very useful for that. Being somewhat OO based it's really easy to open up your internal classes and objects for use by the Python scripter.

I agree with you though - some of the semantics just plain suck.

Thats why we figured we'd allow any language than can be compiled to a dll to be used as a script also. Getting access to our object model is harder but for the hardcore C/C++ (or even cobol) people, well, it keeps em quiet.

It took me a while to come around to the python idea as an embedded thingy but the whole compile first time, run compiled code from then on means it's not as slow (despite the single vm per instance) as a script could be.
For throwing quick routines together to do interesting server side operations it's pretty damn useful.

I don't get the whole pink floyd thing either.
March 4, 2005 6:43 AM
 

Rory said:

Scott -

"What got me was the way you define getters and setters for properties in Ruby.

attr_reader :name, :author, :entries
attr_writer :entries"

See... I'm not sure how I feel about that. I was looking at "Boo," a Pythonesque language built for .NET, and it had a similar mechanism for creating properties. The syntax was totally different, but the idea was the same.

Here's what bothers me - As long as I'm not validating the input (or performing some other action) on values as they're assigned to properties, then what's the point? Might as well just make your variables public.

Is that possible in Ruby? I've looked at a few code samples, but haven't delved too deeply.

Anyway, it seems like a cool construct, but only as long as we're just using properties instead of public variables because "that's how it's done."

Your project sounds interesting, though. Be interesting to see how things progress...
March 4, 2005 7:19 AM
 

Rory said:

Jason -

"Okay, time for me to defend myself"

Not even remotely necessary :)

I just enjoyed our conversation and wanted to write about it.
March 4, 2005 7:21 AM
 

Rory said:

Ron -

"people who draw cartoons and put them on their weblog *SUCK*"

I totally agree :)
March 4, 2005 7:22 AM
 

Rory said:

Aaron -

"OS X overrated?!"

After about three years with it, I'd have to say, yeah - I think it is.

That isn't to say that I don't like it. I actually think it's incredible.

But, I still think it's overrated. Like avocados. I like avocados (sometimes), but think that people get a little too googley-eyed over 'em.

"OS X is about as overrated as the "I'm feeling lucky" button on the Google homepage."

Exactly!

"Please. The power of UNIX, the flexibility of UNIX and the stability of UNIX. OS X ROX!"

Um... I *adore* OS X, but I don't think of it as being all that stable. I've found that, when X crashes, it *crashes*.

I also have much more to gripe about where OS X is concerned, but I'm not going to do it because:

A) I love OS X and don't feel like bashing it

- and -

B) I'm really tired and need to go to bed
March 4, 2005 7:27 AM
 

Rory said:

Ian -

"I don't get the whole pink floyd thing either."

Be careful, my friend - it's not a popular position to take.

You will wear that opinion like a scarlet letter...
March 4, 2005 7:29 AM
 

sil said:

Personally, I don't agree with you, Rory my man, but I made my response <a href="http://www.kryogenix.org/days/2005/03/04/pythonLike">kryogenix.org</a> rather than here...

I'm with you on Floyd, though. And OS X. :)
March 4, 2005 11:12 AM
 

sil said:

(hm. That's http://www.kryogenix.org/days/2005/03/04/pythonLike -- sorry. No preview, though...:))
March 4, 2005 11:13 AM
 

Kris said:

To Rory and anyone else out there who speaks out against Floyd (Dark Side, the Wall, Animals... have you even listened to these albums?!): I'm requesting that you wear a pink P on your forehead so that Floyd fans can recognize you as heretics and proceed with a 70's rock concert beat down in the event of encountering you. I'll be driving off in my I-Roc laughing the whole time! Shine on Crazy Diamond...
March 4, 2005 12:50 PM
 

Greg Low said:

Hi Rory,

Loved the python bit but the Pink Floyd bit - them's fighting words :-)

Regards,

Greg
March 4, 2005 1:03 PM
 

Dave Gil-less(as opposed to more) said:

Python is cool, it's almost like a cleaned-up version of Perl, Perl has too many 'TMTOWTDIs' syntactically(I prefer my languages sugar free).

*** PINK FLOYD ****
They semi-suck, money is about their best song, it shows stretching music out over a longer time doesn't work well if you don't know what you're doing(too much drugs!!). I heard a Tool album, Lateralus, this album is great, it shows how structure can fit over a longer time(although I wouldn't recommend it to a Pink Floyd fan, it's heavier in nature). Basically after the first two minutes of almost all Pink Floyd records you're alseep.

Was this supposed to be about Python?
March 4, 2005 3:22 PM
 

Scott said:

Rory,

"Anyway, it seems like a cool construct, but only as long as we're just using properties instead of public variables because "that's how it's done." "

My understanding is that there is no such thing as a public field in Ruby. It enforces encapsulation. You can define getters and setters for the properties if you need to perform some actions on them. e.g.
def name=(newName)
if newName == "Scott"
@name = "boogerhead"
else
@name = newName
end
end

or read-only
def name
@name
end
March 4, 2005 3:48 PM
 

Josh said:

I had a similar experience with Python: read it, played with it, thought it was kinda neat, but it didn't stick.

But I think you are barking up the wrong tree when you rail against the need to type "self" everywhere. There are so many things that a Python fan could bite back with, regarding unnecessary typing in C# (my preferred lang too). What's with all the braces? Why do you have to declare the type and then the type you are creating all in the same line?

I know the answers, but when you start arguing on the basis of repetitive unnecessary typing, I think Python will win.
March 4, 2005 3:59 PM
 

Cintask Airer said:

careful with that axe Eugene....

March 4, 2005 5:20 PM
 

brian said:

I coulnd't agree more with the Python AND the Pink Floyd remarks!

One of the comments is about the pragmatic programmer’s suggestion to learn a new langauge every year. It is interesting to see those same guys just put out a book on Ruby. I agree with Don Box (http://pluralsight.com/blogs/dbox/archive/2005/02/18/5981.aspx) and I think that and their Subversion book will keep me busy this weekend.

Keep up the Controversy,
Brian
March 4, 2005 5:23 PM
 

Chris Tavares said:

Ok, I gotta defend my favorite language at least a little, here.

1) Python is not "relatively new". The first versions were release in what, '91? The language is almost 15 years old at this point.

2) The mix of procedural/object methods is there for that dreaded thing, backwards compatibility. Remember that "15 years old" thing? There's a lot of old Python code out there that still runs just find on Python 2.4.

3) The ability to do both procedural and OO programming is actually a good thing. You can work procedurally for small stuff like shell scripts, or if you're just starting out and don't get OO yet.

4) The self thing... well, I got nothin. ;-) Just one note - self is NOT a python keyword. When calling a method, the first parameter is always the "self" object. C# hides this implicit parameter, Python does not. As a result, you could name that variable anything you want.

Oh, just remembered WHY the self is explicit - you can attach methods to classes in Python after the fact. So, you could do this:

class C:
def m1( self ):
print "This is m1"

def f( self, s ):
print "This is f, called with " + str( self ) + s

C.f = f

o = C()
o.f( "hello" )

You'll get something like this:
This is f1, called with <__main__.C instance at 0x00C3AA08> and hello

This is a good example, actually, of why I like Python. It's a language with a pleasant syntax for day-to-day work, but just under the hood is a whole lot of power that you usually don't find in languages other than Lisp or Scheme or something else ugly like that.

Granted, you don't need to do this every day, but isn't it cool that you can?

5) The underscores? Well, any special method in Python has the form __xxx__, so at least it stands out. I guess it's just a style thing.

Oh well, that's why all those different languages are out there, right?
March 4, 2005 6:51 PM
 

Joe Duffy said:

Python is merely the new Java. Those who use it are somehow intrinsically cooler than the rest. Like having a bigger schlong or (say) driving a Ferarri.

The only camp worse than these folks are LISP heads. Of course, being a big fan of paranthesis-oriented programming (POP, the new wave), I'm dissing myself.

But I've always held myself in such low regard, so this shouldn't be surprising.

Anyhow. Back to writing about why using Thread.Suspend/Resume is worse than eating monkey turds. Do it and you forfeit your smidgen of a chance of getting into Heaven.
March 4, 2005 7:09 PM
 

Chris Tavares said:

By the way, the next time you guys do a nerd lunch, drop me a line, willya! I'm not that far, and I need to bask in more nerdiness.

Heck, all three of you missed my PADNUG presentation. You owe me! You hear me???
March 5, 2005 9:45 AM
 

Hermann Klinke said:

Hi Rory, once again your totally right. I have not used Python, but planned to try it out because of all the hype that it's sooooo great. You made perfectly valid points that it does suck and thank you for making me not wanting to try it out anymore.
March 5, 2005 10:22 AM
 

Rory said:

Joe -

"Python is merely the new Java. Those who use it are somehow intrinsically cooler than the rest,"

That's a pretty damned good summation :)

I feel the same way, although I think it isn't *quite* as bad as the Java mentality, if only because Python *really is* a kinder, gentler language...
March 5, 2005 7:18 PM
 

Rory said:

Chris -

First of all, thanks for clearing some of the air. I thought Python was newer than that.

I still say some feature drive me nuts, but it makes more sense now.

And, I missed your Padnug presentation because I was on the road for three weeks, my friend!

But, yeah - I think there were a few people we should have called, but it didn't dawn on me until we actually got there. Everything happened pretty quickly.

We'll do gooder next time :)
March 5, 2005 7:20 PM
 

Phil Weber said:

"I would have respected a choice to have ditched all [VB6] hacks, but instead they were carried over to [VB.NET], so now we had the choice of doing things procedurally or Object Orientedally."

Catch my drift? ;-)
March 6, 2005 1:51 AM
 

Anonymous said:

The boo programming language for .NET is very much like python but fixes both the constructor problem and the self problem you mention. It also has some ruby-like features such as true closures.

http://boo.codehaus.org/
May 17, 2005 11:14 PM
 

Colin Alston said:

Missing the point is FUN! (F. U. N. as you might say)

"If self needs to be listed, then why do we have to define it? Why can’t it just be done automatically?"

Why does self need to be included? Let's take your method and apply it to how things really work. Firstly it's not "self" it's whatever you want it to be. When calling an object method, the first parameter is the object. Now let's look at the problem with your mentality and see where it utterly fails.

def foo(arg):
pass

class Bar:
def bar(arg)
pass

We now have a class Bar. But its now useless. In the PHP "LOLZ WOTS ARE A OBJECT?!??!" mentality this is fine, you can simply call methods like
j = Bar(); j.bar(someparam)
but you've broken the object model where the following would work for object prototyping, you've destroyed the "self" parameter and can no longer access an object.
Bar.bar(1) # Who am I??

Bring multiple inheritance and adaptation into the question...
May 9, 2006 7:29 AM
 

TrackBack said:

Python-O-Rama
March 4, 2005 6:45 PM
 

TrackBack said:

Whole-Brain Coding
March 7, 2005 10:13 PM
 

TrackBack said:

Learning Python and Perl
March 8, 2005 3:32 AM
New Comments to this post are disabled

About Rory

I *own* this site, you loser.