For example here's a ~2k line Python project which is a command line finance income and expense tracker: https://github.com/nickjj/plutus/blob/main/src/plutus
It uses about a dozen stdlib modules.
About 25% of the code is using argparse to parse commands and flags. With that said, I tend to prefer code that yields more lines for the sake of clarity. For example this could technically be 1 or 2 lines but I like each parameter being on its own line.
parser_edit.add_argument(
"-s",
"--sort",
default=False,
action="store_true",
help="Sort your profile and show a diff if anything changed",
)It's so much easier to write a simple usage() function that has all help text in one big block, and Getopt with a case block. Anyone can just look at it and edit it without ever looking up documentation.
One nice thing about argparse is it comes with a helper function for mutually exclusive groups that can be optional or required. For example you can have --hello OR --world but not both together.
Python lets you just nest data structures without having to twist your brain. You want a tuple in a list in a dictionary value: you just write it down and can access it with a unified notation. Bam. No reference madness and thinking about contexts. It's a big part of what I typically need to get things done quickly and understand how I did it 5 years later. That has to count for something. Python is boring in that sense, Perl is fun. But that's exactly my problem with it. It's too clever for it's own good and writing it does things to your brain (well at least mine).
That was about the time I stopped using Perl for any new projects. I never wanted to go back.
Powershell is also horribly offended by trying to nest arrays. As is bash.
perl <<'EOF'
my $object = bless sub { my ($s) = @_; if ($s eq "thingy") { return("hello world!") } else { return("goodbye world!") } };
my %hash1 = ( baz => "here we go", foo => $object );
my @array1 = ( undef, undef, undef, \%hash1 );
my %hash2 = ( bar => \@array1 );
my $reference = \%hash2;
print( $reference->{bar}->[3]->{baz}, "\n" );
print( $reference->{bar}->[3]->{foo}->('thingy') , "\n" );
print( $reference->{bar}->[3]->{foo}->('something') , "\n" );
EOF
here we go
hello world!
goodbye world!
Perl being Perl, TMTOWTDI, but you can enforce your own style using linters and formatters.I think the classic Python vs. Perl question ultimately comes down to using what you feel most comfortable with. People are different, and that's totally fine.
Perl falls apart when you need structure and even small projects. For short scripts meant to do what you would use Bash for, it's a godsend. Safer, more portable, less friction.
There seems to very few smart people who agree with this in practice, however.
Those were the days…