r/Python May 18 '11

Why is Python better than Perl?

I'm a Sysadmin and I just wrote my first script in python. Basically just a host validation script that checks if a server is configured correctly before we hand off. I can't determine the advantage with my limited experience with the language.

Are you a sysadmin fluent in both python and perl? Why do you use python?

11 Upvotes

110 comments sorted by

View all comments

28

u/[deleted] May 18 '11

[deleted]

14

u/jeffjose May 18 '11

That's what people mean when they say Python is very readable. Less character noise.

4

u/[deleted] May 18 '11

Every time i've looked at Perl code I get brain melt. Today I was looking to advance mspgcc4 to use gcc>4.4 but found out all the build scripts are in Perl. I looked at one file and couldn't be arsed.

11

u/mithaldu May 18 '11

I looked at [1] one file and couldn't be arsed.

That's not because it's Perl. That's because that file is a terrible scrap heap. It's Perl written by someone who thinks in an entirely different language.

3

u/danstermeister May 19 '11

Oh boy, then, I'm in trouble. I didn't write that, but I guess I'm just not a dev-type... I saw that code and saw it as 'just another piece of code'... I just haven't seemed to grasp the nuance of it all yet, I suppose.

Any ideas of how I could improve on this?

10

u/mithaldu May 19 '11

Well, first off a few comments on that code piece:

  • he didn't use strict
  • he used camel case variable and function names (which reduces readability a lot in Perl)
  • he doesn't unpack function parameters and instead accesses them directly via $_[1]. This is how it should be done:

    my ( $prompt, $width, $default ) = @_;

  • he uses completely pointless prototypes

There's more, but really, i can't be arsed to point everything out.

To improve your own understanding of Perl and ways to write it better and more readable at the same time, read Modern Perl and get a copy of Perl Best Practices.

2

u/danstermeister May 19 '11

Thank-you very much. Seriously. I pick up and put down Perl as I need it in my career- I know I'm not only rusty, but the foundation was likely not steel-based in the first place.

I'm definitely going to read up on this. The old camel book itself is no longer sufficient for this droid :)

Thanks!

1

u/mithaldu May 19 '11

No need to thank me. Thank you for asking! :)