This is part 1 of a 3 part series.
use Switch;- This has got to be the worst implementation of switch/case that I've ever seen. Everyone else uses automatic fallthrough until it hits abreak;. Not Perl! It not only useslast;instead ofbreak;, but it also prohibits fallthrough unless you specifically ask for it or implement it usingnext;. The reasoning behind this? Switch uses the regular expression parser for its arguments instead of having one case line per value like every other language that implements switch/case.
As if the current implementation isn't bad enough, Perl 6 is set to use a different set of keywords:givenandwhen.- Line noise - Perl has an overabundance of variables that use punctuation. For example, there's an operator <> that reads for the current filehandle (defaulting to STDIN). $_ is the "magic" default variable, $/ controls what <> thinks ends a line, setting $\ makes print act like Java's println, $! is the last error from the OS. The
use English;module mitigates this problem somewhat, but it is still a pain. - for/foreach - These functions do not need to be synonyms of each other. I've actually seen people who claim that
for my $object (@objects)is the proper way to write that. It isn't!foreach my $object (@objects)is! This code, while not directly translatable into other languages, is more intuitive for people reading the code. - Things that should be in the core aren't -
use Cwd qw/getcwd/;is rather dumb. cwd/pwd is a common filesystem operation, yet it is not part of the perl core. use constant;-use vars;has finally been changed to our. Why hasn't use constant also gone away? I think havingconst WHATEVER = 5would be a great idea.- mod_perl - Great idea, poor implementation. PHP CGI and mod_php require no code changes to work correctly even on horribly bad code. Why does mod_perl?
- Perl 6 - Copying Java. Switching to a VM? Changing the object delimiter to . ? Why not change the string concat operator to +? Oh, that's right... you can't do that in a weakly typed language. Instead, it's changing to... oh wait, that's right... it keeps changing. It was _ last time I checked, but I bet it changes again before Perl 6 is finalized. The sad part is... Duke Nukem Forever will probably beat Perl 6 to market.
- Arguments to subs - Perl subroutines do not allow named arguments, instead placing all arguments in the magic array @_ or hash %_. Function prototyping only allows you to specify the types of arguments.
elsif- Why is this named elsif and notelseiforelse if?
That's all I can think of for now. I'll probably add more later as I work on the others.
Edit 1: #2 has been updated, #8 is new
Edit 2: #1 has added commentary, #9 has been added
June 26 2006, 07:55:36 UTC 5 years ago
:p
June 26 2006, 08:15:25 UTC 5 years ago
Incidentally, that gives us more than one way to fuck up.
June 26 2006, 11:44:51 UTC 5 years ago
use Cwd qw/chdir/;can be used to change this behavior by replacing perl's chdir with a version that updates $ENV{'PWD'}. However, other modules will not be affected by this change unless they also load chdir from the Cwd module.June 26 2006, 12:59:36 UTC 5 years ago
# Not a clue if this syntax is correct, but it probably gives you the right idea.
sub something {
foreach {
print;
}
}
But in many other situations, you end up having to do:
sub something {
my $name = shift;
my $address = shift;
my $zip = shift;
my $phone = shift;
# Stuff
}
Okay, I admit, there's a way to do this in one line as well, but the point is, why not just have sane variable-passing like every other language? Psh. :(
Anonymous
June 29 2006, 13:11:52 UTC 5 years ago
Well, that's a bit wordy...
It's easier to say:sub something {
my ($name, $address, $zip, $phone) = @_;
}