This post is another X vs. Y. However, unlike the majority of X vs. Y -- heck, let's even start getting more specific and say Perl vs. Python -- debates, this thread will attempt to measure the differences between these two languages by looking at differences on the coding level. Rather than just "well, it's just easier to do task XYZ in Python/Perl" I intend to do a bit of character-by-character analysis (I think you'll see what I mean) to show you why lately I've taken great interest in Python.
In fact, I'm even yearning to understand why Perl still manages to exceed the popularity of Python.
If you think this is a flame against Perl though, you've drastically missed my point. I'm here to present, from a coding standpoint, why I've come to see Python as an extremely cool language...for me, more useful than Perl I believe, and from there, to be shown -- by you, the viewer -- the contrary to my viewpoint.
Allow me to begin:
Perl Python @foo foo my $foo = 1; foo = 1
Python's conditional constructs always look the same, which, when you're the maintenance programmer, is a welcome surprise. They also take up fewer lines.
Perl Python if ($foo) { print "hello world"; }if foo: print "hello, world"if ($foo) { print "hello, world"; }if foo: print "hello, world"
Python's syntax above is not only much simpler (i.e. the function definition syntax of having a function name followed by a parameter list in parenthesis, which is common to many languages), but, because it is part of the function definition itself, it's easy to write programs that automatically generate documentation. In combination with Python's "docstrings" (a string literal placed right after the definition of the function, that python's interpreter parses and puts into the variable func_name.__doc__) automatically generating module documentation is easy, without needing to know any freaky perldoc tags. And for lazy programmers, it's nice to save on the keystrokes too.
Perl Python sub foo { my $arg1 = shift; my @rest_of_args = @_; ...do stuff... }def foo (arg1, rest_of_args): ...do stuff...sub foo { my $arg1 = shift || 0; ...do stuff... }def foo (arg1 = 0): ...do stuff...
In combination with the added typing associated with variable access in Perl, this adds up.
Perl Python $foo->bar(); foo.bar()
The point being, fewer rules to learn == fewer rules to keep in your head.
perlreftut and perlref -- In Python, everything already is a reference. There's no need to learn the tricks of using them. perlvar -- Python's "special variables" are virtually self-documenting. e.g. func_name.__doc__ perlboot and perltoot and perltootC -- Save for perhaps a little blurb thta might equate to a "pythontootC", Python's OO is as obvious as it gets. Want to declare class Foo that inherits from classes Bar and Baz? class Foo(Bar, Baz)...how much easier to you want it? :) perlpod -- docstrings are the only really "special" thing you need to know about documenting your Python code. However, there's nothing "special" about them. You write --> "this function does that" instead of --> # this function does that. perllol -- because everything in Python already is a reference, lists of lists work the way you think they would. [1, 2, 3] becoming an LoL would simply be (as an example) [1, ['foo', 'bar'], 3]. What other syntax would you have expected? :)
Please show me a contrary, and equally backed up, viewpoint on this debate. For reasons already cited "it sucks because it uses whitespace to group statements" or "Perl is better because it has default variables" don't fly. That's 100% pure opinion. The points I've shown above are concrete examples of why, even with best coding practices, character for character, and due to language design issues you will save characters in Python, and also shows specifically why it's easy to write tools to autogenerate Python module documentation without knowing any special documentation syntax.
Warning: If you say something about Perl vs. Python in clear ignorance of, and obviously rarely having used, Python, You Will Be Flamed.
Heh.
In reply to Perl vs. Python: Looking at the Code by mothra
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |