Wednesday, 10 May 2017

Python Vs Perl

Perl vs. Python

  • Variable access -- Pyhton is easy to access the varaible
    PerlPython
    @foofoo
    my $foo = 1;foo = 1
  • Perl makes you type {}'s around your blocks and ()'s around your conditionals,
    PerlPython
    if ($foo) {
        print "hello world";
    }
    if foo:
        print "hello, world"
    if ($foo)
    {
        print "hello, world";
    }
    if foo:
        print "hello, world"
    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 guarantees that you'll type at least one extra character at the end of every line. The ";", of course. 
  • The Perl Way of function/method parameters (AND setting parameter defaults)
    PerlPython
    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...
  • Perl makes you type more to access object properties.
    PerlPython
    $foo->bar();foo.bar()
    In combination with the added typing associated with variable access in Perl, this adds up.

 Perl is a lot older than Python and has a much wider selection modules available.

Perl is harder to handle and debug compared to Python when the code starts to grow.
 Easy to read and write, Large number of frameworks available for web development - (flask, web.py, django, google appengine)

No comments:

Post a Comment