I'm slowly being seduced by Python

by Brian K. Jones

Ok, so I'm not completely sold yet. I still have a boatload of Perl code floating about, and for certain things I'm still writing *new* Perl code. However, I was coerced into using Python for a project I'm working on, and I have to say that I think Python is coming on to me.

I try to ignore the furtive glances, and those times when I could swear it's actually winking at me. I don't acknowledge the beguiling smiles and greetings I get from Python when I open my laptop. I just get down to the business of coding and pretend none of it ever happened. That pretending is getting harder by the day.

Here's the thing. I've been doing all of my sysadmin scripting in perl, awk and shell (sometimes together) for a decade. After 10 years, Perl still doesn't even say "hello" to me. It seems to stand ready to spit my own code all over me whenever I try to talk to it. And just when I'm about ready to call it my friend, just when I think I know it, it completely changes. Well, I'm tired of it. I'm tired of the schizophrenia. I'm tired of the attitude. I'm tired of feeling like a Perl n00b after using it for 10 years.

I'm leaving.

Of course, like lots of relationships, it's complicated. Over the years, Perl and I have spawned offspring that aren't going to just disappear because I decide I don't like Perl anymore. I promise to care for them and keep them up to date.

But from this day forward, I'm going with Python in those places where I can. I *want* to feel confident with a language. I *want* to take advantage of code reuse, self-documenting code, and OO design principles. I *want* to have readable, concise code. I *want* to solve problems that are larger than the every day "please change my shell" requests. I want to build tools. I want to architect solutions. I want to solve some of the problems sysadmins face, but I had to solve my own big problem first: namely, being a self-hating Perl slinger who was never particularly comfortable with how Perl, at a very high level, works.

If you're an admin using Python on a regular basis for your admin scripting, let me know how you think it compares to Perl for equivalent tasks. If you're a Perl coder who has tried and *not* used Python for reasons besides the lack of curly braces, fill us in! If you're a religious zealot for one language and have never used the other, feel free to move on!


10 Comments

Simon Hibbs
2007-04-02 12:21:26
I was moderately adept at Perl and wanted to learn OOP, as I learned to program in the 80s and never cought the OOP bug. However Perl's OO features gave me headaches. I tried learning C# and that helped, but it's way over-engineered for my needs. Python showed me the way, and made experimenting with OOP concepts easy and soon I found I didn't need Perl anymore.


My name is Simon, and I'm a Pythoholic.

Todd Ogasawara
2007-04-02 12:37:10
Python is great. I used it for a number of years to write sysadmin type utilities. However, you might want to take a look at Ruby too (no Rails, just Ruby). I switched over to it to write various utilities for the past year or two and have found it to be a very productive tool.
Dylan
2007-04-02 14:01:53
I would also recommend giving Ruby a whirl. Having used both, I settled with Ruby.
Tim O'Brien
2007-04-04 13:53:09
ruby


Brian Jones: Did you hear that?


Me: No, what?


Brian Jones: A distant whispering "ruby"


Me: Oh that, that's the primal and irresistable call of the wild, anytime anyone posts about Python, the spirit of Ruby makes itself known. You should really heed its magical call.


:-)

Noah Gift
2007-04-09 16:11:15
As a sysadmin/programmer I can't think of using anything BUT python. Ruby and Python have way more in common than different, but I don't get picking Ruby over Python especially since a lot of sysadmin code is a mix of procedural and OO. Also, Python has a huge standard library and has been tested for a LONG time, while Ruby is the new kid on the block. I guess though Ruby is a tad more perlish than Python and that is why some flock to it. They are both fun though :)


Simon Hibbs
2007-04-10 04:48:32
I'm keepign my eye on Ruby, but Python's massive standard library and huge range of external projects such as wxPython, pyGame, Numpy, IronPython, etc give it a huge advantage. I know that whtever I choose to do next with Python, there is going to be a lot of other people's work I can build on and I don't have that confidence with Ruby. I like standing on the backs of giants.
Mandus
2007-04-10 15:10:53
Python, oh Python!


I used to be a Perl programmer, learned Perl back in the early 90's. I still say that I never get the kick out of programming Python that I always get when I do Perl. You know, all the $?, $_ and @_'s, and what have you. But one day I realized that I have a hard time reading my own Perl program, even when it was maybe not more than a year since I wrote it. Before that I had to learn Python, not for sys.admin stuff, but for other scientific work. And it occured to me that I never had that problem with Python. From that day onwards, I do Python for sys.admin work. I can still write some Perl code for having fun, but not for serious bread and butter programming.


Talking about OO, I learned OO in Simula, then moved on to C++ and Java. OO in Perl just feel awkward. Even when Tom Christensen tells me in tutorials that it is nice and right and everything. To me, it don't make sense. Python again, feels just right, spot on.


So, I used to be a Perl man, I am now a Python man. And I will be a long time. Of course, I will still use bash, awk, and sed for smaller things and prototyping. But Python, oh python, when I need to do something that should last, scale and improve over time.


Btw, are there anyone else out there who goes to events like Lisa, Usenix, or the like, and also feel it is strange that there are so little Python going on there? Maybe we should throw a bofh next time around?

Kevin Clark
2007-04-17 13:46:14
I'm still a big fan of Perl for various hacks.


1: I'm already familiar with C/sed/ask/sh. Perl's syntax clearly is derived from these things. I like the fact that I don't need to learn another new syntax in order to Get Work Done.


2: Aside from one-liners (which I either write to show people how clever I am or as needed write-once/run-once/throw-away code), I have *never* had a hard time understanding my old Perl code. Everybody is entitled to their own opinion, and mine is that people who can't understand the code that they wrote 4 months/years ago are people who will suffer from this problem using any language.


3: Perl's regexp support and CPAN modules are excellent!


draegtun
2007-04-28 06:31:08
Its always good to experience something different and learn new some funky new tricks.


However for the reasons u give I'm not sure if giving up the old dog (Perl) will necessarily achieve what u want. Check out books like "Perl Best Practises" & "Higher Order Perl". These books provide excellent insight into writing better Perl code. Even if u do eventually move lock, stock and barrel to Python u will still find the concepts in these books useful!


From Python perspective... I can only comment that I tried it a few years ago and found the white space thing just too difficult to overcome. Horses for courses.


I still use Perl has my main tool/language... however I am warming to Ruby at the moment! (as mentioned in previous comments u may find Ruby a lot easier to get into and use alongside Perl).


Remember old dogs are faithful so Perl will still be around should u need it ;-)


/I3az/

Mohamed Hussein
2007-06-20 12:27:00
Ruby is another awesome language that can help you get things done really fast. I like how fast you can write useful things in ruby. I like its strong OO features and I like how easy it is to reuse code and I look forward to more and more packages and modules


I like python, I had hard time in the begining with the indentation, but as I learned more I liked it more. There are certain things about python that somewhat enforces clean programming.


I haven't completely abandoned perl, when I need something fast and I don't know how to do it in ruby already I fall back to perl.