• Home

Logo

Navigation
  • Home
  • Articles
    • Content Writing
    • Design
    • General
    • Internet Marketing
    • Social Media
    • Tools and Tips
    • Usability
    • Web Hosting Articles
  • Tutorials
    • AJAX Tutorials
    • ASP Tutorials
    • C# Tutorials
    • CGI and Perl Tutorials
    • CSS Tutorials
    • Flash Tutorials
    • HTML Tutorials
    • Illustrator Tutorials
    • Java Tutorials
    • JavaScript Tutorials
    • Linux Tutorials
    • Miscellaneous Tutorials
    • MySQL Tutorials
    • Photoshop Tutorials
    • PHP Tutorials
    • Python Tutorials
    • Wireless Tutorials
    • WordPress Tutorials
    • XML Tutorials
  • Scripts
    • AJAX Scripts
    • ASP Scripts
    • ASP.NET Scripts
    • CGI & Perl Scripts
    • Flash Scripts
    • Java Scripts
    • JavaScript Scripts
    • PHP Scripts
    • Python Scripts
    • Remotely Hosted
    • Tools and Utilities
    • XML Scripts
  • Answers
  • Online Services
  • Tools

Python vs. Perl

By Tony Lawrence | on Apr 25, 2005 | 0 Comment
CGI and Perl Tutorials Python Tutorials
  • Tweet
  • Share
  • Tweet
  • Share

Python vs. Perl

First Impressions

I went to http://www.python.org/doc/current/index.htmland used the excellent tutorial there. I found things to like and things to dislike immediately:

Liked

• That object methods are the default, not something tacked on:

a=['abc','def','ghijkl']

print "Before Append",a
a.append('hello')
print "After Append",a

...

Before Append ['abc', 'def', 'ghijkl']
After Append ['abc', 'def', 'ghijkl', 'hello']

There’s a whole boatload of built-in methods: see http://www.python.org/doc/current/tut/node7.html. I’m not going to say I like these better than the Perl functions that do similar things, but I certainly have no problems with these and can see good use for them.

• That integer math is the default unless one or more of the operands isn’t an integer:

print 7 / 2

print 7.0 / 2

...

3
3.5

• That semicolons at the end of lines are optional: any of these are fine:

print 7/2;print 7/2.0


print 7/2;
print 7/2.0

print 7/2
print 7/2.0

Leaving off semicolons is a common Perl goof..

• Indentation syntax. Everything indented is part of what happens when “mytest” is not 0 or null:

mytest=1

if mytest:
print "mytest ",
print "is set"

print "hello ",

Oddly, this is something most Perl types really hate, but I’d find it easy to get used to. Since most of us tend to indent code within blocks anyway, it seems reasonable to me to dispense with the braces and just use the indentation.

• Default argument values for functions:

def foo(prompt=”huh?”, count=2):

print prompt,count

foo()

foo("go","seven")
foo(count=89)

...
huh? 2
go seven
huh? 89

I really like that.

• Exception handling. I like “try/except” logic (apparently Perl 6 has this too);

Disliked

• Variables. I don’t like the C-ish variable names. I LIKE that Perl requires a $, @ or whatever ahead of a variable name – it makes it stand out. I also like that Perl’s $a is different than @a etc.

• Data types. Setting a one value tuple is absolutely ugly:

this='abc','def',0;

print this, len(this)
this='hello' # NOT a tuple
print this, len(this)
this='hello', # Now it is
print this, len(this)

...
('abc', 'def', 0) 3
hello 5
('hello',) 1

This is a consequence of not having data prefixes or formal declarations.

• No “a++” or “a–”. Sheesh.

• No “$_”. There’s _, which apparently isn’t quite the same – unless I misunderstand, which is certainly possible at this point.

Overall, I think I’ll stick with Perl. I can see Eric Raymond’s argument for larger projects, but I don’t do large projects anymore and I just find Perl’s wild versatility and lack of insistence (More Than One Way To Do It) more attractive than more structured languages. But Python certain does have its appealing aspects, so I’ll probably dabble with it here and there.

I certainly cannot agree with some who insist that Python is easier to read or understand than Perl. That’s just ridiculous: neither of them add anything to helping understand someone else’s code. Perl isn’t any more “cryptic” than Python. Nor can I understand the attitude that Perl is deficient because you can do things in multiple ways. If you insist on such structure, enforce it upon yourself: nobody is stopping you. I do understand that for larger projects, with multiple people involved, structure is more necessary.

All in all, I wouldn’t be terribly upset if I got “stuck” with something that had to be done in Python. It’s a very reasonable scripting tool and does have some very nice features.

Share this story:
  • tweet

Author Description

No Responses to “Python vs. Perl”

You must be logged in to post a comment.

Connect With Us

RSSSubscribe 1,238Followers 492Likes
  • Popular
  • Recent
  • Comments
  • Creating Energy Spheres in Photoshop

    Apr 15, 2008 - 96 Comments
  • Easy Screen Scraping in PHP with the Simple HTML DOM Library

    Aug 6, 2008 - 20 Comments
  • Calculating date difference more precisely in PHP

    Mar 7, 2008 - 13 Comments
  • When Does Hosting Your Website in the Cloud Make Sense?

    Oct 8, 2010 - 2 Comments
  • Fun with the Microsoft Managed Extensibility Framework Part 2

    Oct 6, 2010 - 0 Comment
  • Fun with the Microsoft Managed Extensibility Framework Part 1

    Sep 22, 2010 - 0 Comment
  • Website Management on the go with the iPad

    I appreciated your post, but I was looking for something I didn't...
    November 24, 2012 - drmoderator
  • Creating Energy Spheres in Photoshop

    I'm a little stuck down here especially at the step of creating the...
    November 23, 2012 - sarah
  • Running background processes in PHP

    Can you give an example? As see it, you can use this only when you...
    November 16, 2012 - Shaked Klein Orbach
Developer Resources
  • Tutorial Directory
  • Learn HTML
  • Learn PHP
  • Learn CSS
  • Learn AJAX
  • Learn JavaScript
  • Learn Pear
  • White Papers
  • Resources
    • NetVisits Web Directory
    • Realtor Pixels
    • Answers On The Run
    • Ask A Geek
  • Recent Posts

    • When Does Hosting Your Website in the Cloud Make Sense?
    • Fun with the Microsoft Managed Extensibility Framework Part 2
    • Fun with the Microsoft Managed Extensibility Framework Part 1
    • Website Management on the go with the iPad
    • Code Contracts in C# 4.0 – Part 1

    Calendar

    May 2013
    M T W T F S S
    « Oct    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

    Recent Comments

    • drmoderator on Website Management on the go with the iPad
    • sarah on Creating Energy Spheres in Photoshop
    • Shaked Klein Orbach on Running background processes in PHP
    • Thomas Cuvillier on How To Upload Files Using PHP
    • rizal aditya on Extracting text from Word Documents via PHP and COM
    • Home
    © 2003 - 2013 DeveloperTutorials.com. All Rights Reserved. Privacy Policy.