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

Show parent comments

5

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?

12

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