my $obj = Some::Class->new(@constructor_params);
with:
my $obj = new Some::Class @constructor_params;
making the C++ people feel right at home. Of course, in Perl,
there's nothing special about the name
new, but at least the syntax is hauntingly
familiar.
Why the previous "generally"
caveat? Well, if the instance is something more complicated than a
simple scalar variable:
$somehash->{$somekey}->[42]->instance_method(@parms);
then you can't just swap it around like:
instance_method $somehash->{$somekey}->[42] @parms;
instance_method { $somehash->{$somekey}->[42] } @parms;
And that goes from simple to uglier in one step.
There's another downside: ambiguous parsing. When we
developed the classroom materials concerning indirect object
references, we wrote:
my $cow = Cow->named("Bessie");
print name $cow, " eats.\n";
because we were thinking about the indirect object equivalents for:
my $cow = Cow->named("Bessie");
print $cow->name, " eats.\n";
Unquoted string "name" may clash with future reserved word at ./foo line 92.
Name "main::name" used only once: possible typo at ./foo line 92.
print( ) on unopened filehandle name at ./foo line 92.
Ahh, so that line was being parsed as:
print name ($cow, " eats.\n");
In other words, print the list of items to the filehandle named
name. That's clearly not what we
wanted, so we had to add additional syntax to disambiguate the call.