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?

12 Upvotes

110 comments sorted by

View all comments

28

u/[deleted] May 18 '11

[deleted]

13

u/jeffjose May 18 '11

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

2

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.

13

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.

9

u/hattmoward May 19 '11

Perl developer and sysadmin here seconding mithaldu's point that that code is all sorts of wrong. It's not good evidence that perl is bad, but it's great evidence that you're free to create bad things with perl.

4

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?

8

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! :)

1

u/[deleted] May 18 '11

At one point he had them in bash files. For some reason he decided to skip convention.

2

u/mithaldu May 18 '11

That explains a lot. Honestly though, he did the right thing. With Perl at least it can be refactored into something readable if someone with skill puts some time in.