Date: 2009jun24
Q. Got any Perl 6 suggestions?
A. Perl 5 is great but some things just make no sense.
1. Parameters passing
You can not do:
sub myfunc($a, $b, $c) {
print $a, $b, $c;
}
You must do:
sub myfunc($$$) {
my($a, $b, $c) = @_;
print $a, $b, $c;
}
Its redundant! You have to say the types of the parameters twice.
And its error prone.
2. All code must be in braces.
You can not do:
if ($something) print "Hello\n";
Instead, you must do:
if ($something) { print "Hello\n"; }
No other common language make you do that.
3. Array element access.
If you have:
my(@a);
You access elements like this:
print $a[5];
More sensible would be:
print @a[5];
4. Perl has a great variety of ways to quote but one that's missing
is a heredoc that does not interpret variables. For example:
use strict;
print <<EOF;
see you @the movie
EOF
Will give an error because their is no array called @the
Maybe using a single quote (') could mean: don't interpret.
print <<'EOF;
see you @the movie
EOF
5. Official true and false.
I am don't like using 1 and 0.
6. A === operator for comparing references.
Like javaScript has.
7. A real switch statement like C has. But actually not requiring the break
would be better. Want:
Old code:
if ($a eq 'one') { print "ONE"; }
elsif ($a eq 'two') { print "TWO"; }
elsif ($a eq 'three') { print "THREE"; }
Proposed code:
switch($a)
{
case "one":print "ONE";
case "two": print "TWO";
case "three": { print "THREE"; } # Brackets are optional
}
8. More comments /* */ and //